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

InterleavedBuffer: Use Uint32Array for serializing ArrayBuffer.

Mugen87 5 жил өмнө
parent
commit
90c545e41c

+ 1 - 17
src/core/InterleavedBuffer.js

@@ -112,7 +112,7 @@ Object.assign( InterleavedBuffer.prototype, {
 
 		if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
 
-			data.arrayBuffers[ this.array.buffer._uuid ] = arrayBufferToBase64( this.array.buffer );
+			data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
 
 		}
 
@@ -129,20 +129,4 @@ Object.assign( InterleavedBuffer.prototype, {
 
 } );
 
-function arrayBufferToBase64( buffer ) {
-
-	let binary = '';
-	const bytes = new Uint8Array( buffer );
-
-	for ( let i = 0, l = bytes.byteLength; i < l; i ++ ) {
-
-		binary += String.fromCharCode( bytes[ i ] );
-
-	}
-
-	return window.btoa( binary );
-
-}
-
-
 export { InterleavedBuffer };

+ 1 - 17
src/loaders/BufferGeometryLoader.js

@@ -86,7 +86,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 			const arrayBuffers = json.arrayBuffers;
 			const arrayBuffer = arrayBuffers[ uuid ];
 
-			const ab = base64ToArrayBuffer( arrayBuffer );
+			const ab = new Uint32Array( arrayBuffer ).buffer;
 
 			arrayBufferMap[ uuid ] = ab;
 
@@ -215,22 +215,6 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
 
 } );
 
-function base64ToArrayBuffer( base64 ) {
-
-	const binaryString = window.atob( base64 );
-	const length = binaryString.length;
-	const bytes = new Uint8Array( length );
-
-	for ( let i = 0; i < length; i ++ ) {
-
-		bytes[ i ] = binaryString.charCodeAt( i );
-
-	}
-
-	return bytes.buffer;
-
-}
-
 const TYPED_ARRAYS = {
 	Int8Array: Int8Array,
 	Uint8Array: Uint8Array,