Quellcode durchsuchen

BufferAttribute: onUpload callback to callback setter.
/cc @aardgoose

Mr.doob vor 8 Jahren
Ursprung
Commit
85ab4d1d4d

+ 5 - 3
examples/webgl_buffergeometry.html

@@ -179,9 +179,11 @@
 
 				}
 
-				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
-				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
-				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
+				function disposeArray() { this.array = null; }
+
+				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).onUpload( disposeArray ) );
+				geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).onUpload( disposeArray ) );
+				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).onUpload( disposeArray ) );
 
 				geometry.computeBoundingSphere();
 

+ 9 - 1
src/core/BufferAttribute.js

@@ -26,7 +26,7 @@ function BufferAttribute( array, itemSize, normalized ) {
 	this.dynamic = false;
 	this.updateRange = { offset: 0, count: - 1 };
 
-	this.onUpload = null;
+	this.onUploadCallback = function () {};
 
 	this.version = 0;
 
@@ -321,6 +321,14 @@ BufferAttribute.prototype = {
 
 	},
 
+	onUpload: function ( callback ) {
+
+		this.onUploadCallback = callback;
+
+		return this;
+
+	},
+
 	clone: function () {
 
 		return new this.constructor().copy( this );

+ 1 - 5
src/renderers/webgl/WebGLObjects.js

@@ -126,11 +126,7 @@ function WebGLObjects( gl, properties, info ) {
 		attributeProperties.type = type;
 		attributeProperties.version = data.version;
 
-		if ( data.onUpload !== null ) {
-
-			data.onUpload();
-
-		}
+		data.onUploadCallback();
 
 	}