2
0
Эх сурвалжийг харах

Allow user to copy full buffer with `gl.bufferData` (#9631)

* provide a means of copying the full buffer instead of just sub ranges

* use new API with setArray and needsFullBuffer

* rebuild full buffer contents when version is zero, set version to zero when array changes

* remove fullBuffer parameter from interleaved attrib

* revert comment to original

* revert earlier changes and just stick to bufferData for all non dynamic geometry

* remove spacing to clean up PR
Matt DesLauriers 8 жил өмнө
parent
commit
348b72eefe

+ 13 - 0
src/core/BufferAttribute.js

@@ -42,6 +42,19 @@ BufferAttribute.prototype = {
 
 	},
 
+	setArray: function ( array ) {
+
+		if ( Array.isArray( array ) ) {
+
+			throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
+
+		}
+
+		this.count = array !== undefined ? array.length / this.itemSize : 0;
+		this.array = array;
+
+	},
+
 	setDynamic: function ( value ) {
 
 		this.dynamic = value;

+ 13 - 0
src/core/InterleavedBuffer.js

@@ -31,6 +31,19 @@ InterleavedBuffer.prototype = {
 
 	},
 
+	setArray: function ( array ) {
+
+		if ( Array.isArray( array ) ) {
+
+			throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
+
+		}
+
+		this.count = array !== undefined ? array.length / this.stride : 0;
+		this.array = array;
+
+	},
+
 	setDynamic: function ( value ) {
 
 		this.dynamic = value;

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

@@ -93,7 +93,11 @@ function WebGLObjects( gl, properties, info ) {
 
 		gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
 
-		if ( data.dynamic === false || data.updateRange.count === - 1 ) {
+		if ( data.dynamic === false ) {
+
+			gl.bufferData( bufferType, data.array, gl.STATIC_DRAW );
+
+		} else if ( data.updateRange.count === - 1 ) {
 
 			// Not using update ranges