瀏覽代碼

InstancedBufferGeometry.maxInstancedCount => .instanceCount

WestLangley 5 年之前
父節點
當前提交
107a6bb2a5

+ 2 - 2
docs/api/en/core/InstancedBufferGeometry.html

@@ -24,9 +24,9 @@
 		<h2>Properties</h2>
 		<p>See [page:BufferGeometry] for inherited properties.</p>
 
-		<h3>[property:Number maxInstancedCount]</h3>
+		<h3>[property:Number instanceCount]</h3>
 		<p>
-			Default is *undefined*.
+			Default is *Infinity*.
 		</p>
 
 		<h2>Methods</h2>

+ 2 - 2
docs/api/zh/core/InstancedBufferGeometry.html

@@ -24,9 +24,9 @@
 		<h2>属性</h2>
 		<p>继承属性详见 [page:BufferGeometry]。</p>
 
-		<h3>[property:Number maxInstancedCount]</h3>
+		<h3>[property:Number instanceCount]</h3>
 		<p>
-			默认值是 *undefined*。
+			默认值是 *Infinity*。
 		</p>
 
 		<h2>方法</h2>

+ 2 - 2
examples/webgl_buffergeometry_instancing.html

@@ -145,7 +145,7 @@
 			}
 
 			var geometry = new THREE.InstancedBufferGeometry();
-			geometry.maxInstancedCount = instances; // set so its initalized for dat.GUI, will be set in first draw otherwise
+			geometry.instanceCount = instances; // set so its initalized for dat.GUI, will be set in first draw otherwise
 
 			geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
 
@@ -191,7 +191,7 @@
 			//
 
 			var gui = new GUI( { width: 350 } );
-			gui.add( geometry, 'maxInstancedCount', 0, instances );
+			gui.add( geometry, 'instanceCount', 0, instances );
 
 			//
 

+ 20 - 0
src/Three.Legacy.js

@@ -26,6 +26,7 @@ import {
 	BufferAttribute
 } from './core/BufferAttribute.js';
 import { BufferGeometry } from './core/BufferGeometry.js';
+import { InstancedBufferGeometry } from './core/InstancedBufferGeometry.js';
 import { InterleavedBuffer } from './core/InterleavedBuffer.js';
 import { Face3 } from './core/Face3.js';
 import { Geometry } from './core/Geometry.js';
@@ -1369,6 +1370,25 @@ Object.defineProperties( BufferGeometry.prototype, {
 
 } );
 
+Object.defineProperties( InstancedBufferGeometry.prototype, {
+
+	maxInstancedCount: {
+		get: function () {
+
+			console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
+			return this.instanceCount;
+
+		},
+		set: function ( value ) {
+
+			console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
+			this.instanceCount = value;
+
+		}
+	}
+
+} );
+
 Object.defineProperties( Raycaster.prototype, {
 
 	linePrecision: {

+ 1 - 1
src/core/InstancedBufferGeometry.d.ts

@@ -8,7 +8,7 @@ export class InstancedBufferGeometry extends BufferGeometry {
 	constructor();
 
 	groups: { start: number; count: number; instances: number }[];
-	maxInstancedCount: number;
+	instanceCount: number;
 
 	addGroup( start: number, count: number, instances: number ): void;
 

+ 3 - 3
src/core/InstancedBufferGeometry.js

@@ -9,7 +9,7 @@ function InstancedBufferGeometry() {
 	BufferGeometry.call( this );
 
 	this.type = 'InstancedBufferGeometry';
-	this.maxInstancedCount = undefined;
+	this.instanceCount = Infinity;
 
 }
 
@@ -23,7 +23,7 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry
 
 		BufferGeometry.prototype.copy.call( this, source );
 
-		this.maxInstancedCount = source.maxInstancedCount;
+		this.instanceCount = source.instanceCount;
 
 		return this;
 
@@ -39,7 +39,7 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry
 
 		var data = BufferGeometry.prototype.toJSON.call( this );
 
-		data.maxInstancedCount = this.maxInstancedCount;
+		data.instanceCount = this.instanceCount;
 
 		data.isInstancedBufferGeometry = true;
 

+ 7 - 5
src/renderers/WebGLRenderer.js

@@ -868,7 +868,9 @@ function WebGLRenderer( parameters ) {
 
 		} else if ( geometry.isInstancedBufferGeometry ) {
 
-			renderer.renderInstances( geometry, drawStart, drawCount, geometry.maxInstancedCount );
+			var instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
+
+			renderer.renderInstances( geometry, drawStart, drawCount, instanceCount );
 
 		} else {
 
@@ -927,9 +929,9 @@ function WebGLRenderer( parameters ) {
 
 							state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
 
-							if ( geometry.maxInstancedCount === undefined ) {
+							if ( geometry._maxInstanceCount === undefined ) {
 
-								geometry.maxInstancedCount = data.meshPerAttribute * data.count;
+								geometry._maxInstanceCount = data.meshPerAttribute * data.count;
 
 							}
 
@@ -948,9 +950,9 @@ function WebGLRenderer( parameters ) {
 
 							state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
 
-							if ( geometry.maxInstancedCount === undefined ) {
+							if ( geometry._maxInstanceCount === undefined ) {
 
-								geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
+								geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
 
 							}