Browse Source

VOXLoader: Fixed chunk parsing.

Mr.doob 4 years ago
parent
commit
a36141f54a
1 changed files with 12 additions and 12 deletions
  1. 12 12
      examples/jsm/loaders/VOXLoader.js

+ 12 - 12
examples/jsm/loaders/VOXLoader.js

@@ -51,7 +51,7 @@ class VOXLoader extends Loader {
 
 		const data = new DataView( buffer );
 
-		const id = data.getInt32( 0, true );
+		const id = data.getUint32( 0, true );
 		const version = data.getUint32( 4, true );
 
 		if ( id !== 542658390 || version !== 150 ) {
@@ -107,18 +107,18 @@ class VOXLoader extends Loader {
 
 			for ( let j = 0; j < 4; j ++ ) {
 
-				id += String.fromCharCode( data.getInt8( i ++, true ) );
+				id += String.fromCharCode( data.getUint8( i ++, true ) );
 
 			}
 
-			const chunkSize = data.getInt32( i, true ); i += 4;
-			data.getInt32( i, true ); i += 4; // childChunks
+			const chunkSize = data.getUint32( i, true ); i += 4;
+			data.getUint32( i, true ); i += 4; // childChunks
 
 			if ( id === 'SIZE' ) {
 
-				const x = data.getInt32( i, true ); i += 4;
-				const y = data.getInt32( i, true ); i += 4;
-				const z = data.getInt32( i, true ); i += 4;
+				const x = data.getUint32( i, true ); i += 4;
+				const y = data.getUint32( i, true ); i += 4;
+				const z = data.getUint32( i, true ); i += 4;
 
 				chunk = {
 					palette: DEFAULT_PALETTE,
@@ -131,8 +131,8 @@ class VOXLoader extends Loader {
 
 			} else if ( id === 'XYZI' ) {
 
-				const numVoxels = data.getInt32( i, true ); i += 4;
-				chunk.data = new Int8Array( buffer, i, numVoxels * 4 );
+				const numVoxels = data.getUint32( i, true ); i += 4;
+				chunk.data = new Uint8Array( buffer, i, numVoxels * 4 );
 
 				i += numVoxels * 4;
 
@@ -142,7 +142,7 @@ class VOXLoader extends Loader {
 
 				for ( let j = 0; j < 256; j ++ ) {
 
-					palette[ j + 1 ] = data.getInt32( i, true ); i += 4;
+					palette[ j + 1 ] = data.getUint32( i, true ); i += 4;
 
 				}
 
@@ -278,7 +278,7 @@ class VOXDataTexture3D extends DataTexture3D {
 
 		const array = new Uint8Array( size.x * size.y * size.z );
 
-		for ( let j = 0, k = 0; j < data.length; j += 4, k ++ ) {
+		for ( let j = 0; j < data.length; j += 4 ) {
 
 			const x = data[ j + 0 ];
 			const y = data[ j + 1 ];
@@ -286,7 +286,7 @@ class VOXDataTexture3D extends DataTexture3D {
 
 			const index = x + ( y * offsety ) + ( z * offsetz );
 
-			array[ index ] = 255.0;
+			array[ index ] = 255;
 
 		}