瀏覽代碼

InstancedMesh: Exposed count property.

Mr.doob 5 年之前
父節點
當前提交
df3a92e849
共有 3 個文件被更改,包括 9 次插入2 次删除
  1. 6 1
      examples/webgl_instancing.html
  2. 2 0
      src/objects/InstancedMesh.js
  3. 1 1
      src/renderers/WebGLRenderer.js

+ 6 - 1
examples/webgl_instancing.html

@@ -13,6 +13,7 @@
 			import * as THREE from '../build/three.module.js';
 
 			import Stats from './jsm/libs/stats.module.js';
+			import { GUI } from './jsm/libs/dat.gui.module.js';
 
 			var camera, scene, renderer, stats;
 
@@ -36,7 +37,6 @@
 				// check overdraw
 				// var material = new THREE.MeshBasicMaterial( { color: 0xff0000, opacity: 0.1, transparent: true } );
 
-
 				var loader = new THREE.BufferGeometryLoader();
 				loader.load( 'models/json/suzanne_buffergeometry.json', function ( geometry ) {
 
@@ -46,6 +46,11 @@
 					mesh = new THREE.InstancedMesh( geometry, material, count );
 					scene.add( mesh );
 
+					//
+
+					var gui = new GUI();
+					gui.add( mesh, 'count', 0, count );
+
 				} );
 
 				//

+ 2 - 0
src/objects/InstancedMesh.js

@@ -11,6 +11,8 @@ function InstancedMesh( geometry, material, count ) {
 
 	this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
 
+	this.count = count;
+
 }
 
 InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {

+ 1 - 1
src/renderers/WebGLRenderer.js

@@ -865,7 +865,7 @@ function WebGLRenderer( parameters ) {
 
 		if ( object.isInstancedMesh ) {
 
-			renderer.renderInstances( geometry, drawStart, drawCount, object.instanceMatrix.count );
+			renderer.renderInstances( geometry, drawStart, drawCount, object.count );
 
 		} else if ( geometry.isInstancedBufferGeometry ) {