Skip to content

Commit

Permalink
VOXLoader: Fixed chunk parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Feb 16, 2021
1 parent 189ab49 commit a36141f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/jsm/loaders/VOXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -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;

}

Expand Down Expand Up @@ -278,15 +278,15 @@ 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 ];
const z = data[ j + 2 ];

const index = x + ( y * offsety ) + ( z * offsetz );

array[ index ] = 255.0;
array[ index ] = 255;

}

Expand Down

0 comments on commit a36141f

Please sign in to comment.