瀏覽代碼

WebGLRenderer: Do not upload MorphTargets with 0 influence.

Mr.doob 10 年之前
父節點
當前提交
7682c93fe3
共有 3 個文件被更改,包括 21 次插入8 次删除
  1. 6 0
      src/core/BufferGeometry.js
  2. 5 4
      src/renderers/WebGLRenderer.js
  3. 10 4
      src/renderers/webgl/WebGLObjects.js

+ 6 - 0
src/core/BufferGeometry.js

@@ -49,6 +49,12 @@ THREE.BufferGeometry.prototype = {
 
 	},
 
+	removeAttribute: function ( name ) {
+
+		delete this.attributes[ name ];
+
+	},
+
 	get offsets() {
 
 		console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );

+ 5 - 4
src/renderers/WebGLRenderer.js

@@ -902,9 +902,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( geometryAttribute !== undefined ) {
 
-					var size = geometryAttribute.itemSize;
 					state.enableAttribute( programAttribute );
 
+					var size = geometryAttribute.itemSize;
 					var buffer = objects.getAttributeBuffer( geometryAttribute );
 
 					if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
@@ -1051,15 +1051,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 				var influence = activeInfluences[ i ];
 				morphInfluences[ i ] = influence[ 0 ];
 
-
 				if ( influence[ 0 ] !== 0 ) {
 
 					var attribute = geometry.morphAttributes[ influence[ 1 ] ];
 
-					objects.updateAttribute( attribute );
-
 					geometry.addAttribute( 'morphTarget' + i, attribute );
 
+				} else {
+
+					geometry.removeAttribute( 'morphTarget' + i );
+
 				}
 
 			}

+ 10 - 4
src/renderers/webgl/WebGLObjects.js

@@ -87,8 +87,6 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
 
 		}
 
-		//
-
 		var attributes = geometry.attributes;
 
 		for ( var name in attributes ) {
@@ -97,6 +95,16 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
 
 		}
 
+		// morph targets
+
+		var morphAttributes = geometry.morphAttributes;
+
+		for ( var i = 0, l = morphAttributes.length; i < l; i ++ ) {
+
+			updateAttribute( morphAttributes[ i ], i );
+
+		}
+
 	}
 
 	function updateAttribute( attribute, name ) {
@@ -196,8 +204,6 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
 
 	};
 
-	this.updateAttribute = updateAttribute;
-
 	this.clear = function () {
 
 		objects = {};