فهرست منبع

Merge pull request #11980 from Mugen87/dev

InstancedBufferGeometry: Fix .copy() and .clone()
Mr.doob 7 سال پیش
والد
کامیت
1e31109ec1
2فایلهای تغییر یافته به همراه13 افزوده شده و 38 حذف شده
  1. 7 4
      examples/webgl_buffergeometry_instancing_billboards.html
  2. 6 34
      src/core/InstancedBufferGeometry.js

+ 7 - 4
examples/webgl_buffergeometry_instancing_billboards.html

@@ -126,7 +126,7 @@
 			renderer = new THREE.WebGLRenderer();
 
 			if ( renderer.extensions.get( 'ANGLE_instanced_arrays' ) === false ) {
-				document.getElementById( "notSupported" ).style.display = "";
+				document.getElementById( 'notSupported' ).style.display = '';
 				return false;
 			}
 
@@ -138,8 +138,11 @@
 
 			scene = new THREE.Scene();
 
+			var circleGeometry = new THREE.CircleBufferGeometry( 1, 6 );
+
 			geometry = new THREE.InstancedBufferGeometry();
-			geometry.copy( new THREE.CircleBufferGeometry( 1, 6 ) );
+			geometry.index = circleGeometry.index;
+			geometry.attributes = circleGeometry.attributes;
 
 			var particleCount = 75000;
 
@@ -153,11 +156,11 @@
 
 			}
 
-			geometry.addAttribute( "translate", new THREE.InstancedBufferAttribute( translateArray, 3, 1 ) );
+			geometry.addAttribute( 'translate', new THREE.InstancedBufferAttribute( translateArray, 3, 1 ) );
 
 			material = new THREE.RawShaderMaterial( {
 				uniforms: {
-					map: { value: new THREE.TextureLoader().load( "textures/sprites/circle.png" ) },
+					map: { value: new THREE.TextureLoader().load( 'textures/sprites/circle.png' ) },
 					time: { value: 0.0 }
 				},
 				vertexShader: document.getElementById( 'vshader' ).textContent,

+ 6 - 34
src/core/InstancedBufferGeometry.js

@@ -19,47 +19,19 @@ InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry
 
 	isInstancedBufferGeometry: true,
 
-	addGroup: function ( start, count, materialIndex ) {
-
-		this.groups.push( {
-
-			start: start,
-			count: count,
-			materialIndex: materialIndex
-
-		} );
-
-	},
-
 	copy: function ( source ) {
 
-		var index = source.index;
-
-		if ( index !== null ) {
-
-			this.setIndex( index.clone() );
+		BufferGeometry.prototype.copy.call( this, source );
 
-		}
+		this.maxInstancedCount = source.maxInstancedCount;
 
-		var attributes = source.attributes;
-
-		for ( var name in attributes ) {
-
-			var attribute = attributes[ name ];
-			this.addAttribute( name, attribute.clone() );
-
-		}
-
-		var groups = source.groups;
-
-		for ( var i = 0, l = groups.length; i < l; i ++ ) {
+		return this;
 
-			var group = groups[ i ];
-			this.addGroup( group.start, group.count, group.materialIndex );
+	},
 
-		}
+	clone: function () {
 
-		return this;
+		return new this.constructor().copy( this );
 
 	}