Skip to content

Commit

Permalink
[DRACOLoader] Improve performance with new GetArray methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Don McCurdy committed Sep 22, 2020
1 parent 77b15c1 commit b073104
Show file tree
Hide file tree
Showing 8 changed files with 349 additions and 435 deletions.
55 changes: 38 additions & 17 deletions examples/js/libs/draco/draco_decoder.js

Large diffs are not rendered by default.

Binary file modified examples/js/libs/draco/draco_decoder.wasm
Binary file not shown.
233 changes: 104 additions & 129 deletions examples/js/libs/draco/draco_wasm_wrapper.js

Large diffs are not rendered by default.

49 changes: 33 additions & 16 deletions examples/js/libs/draco/gltf/draco_decoder.js
100755 → 100644

Large diffs are not rendered by default.

Binary file modified examples/js/libs/draco/gltf/draco_decoder.wasm
100755 → 100644
Binary file not shown.
223 changes: 104 additions & 119 deletions examples/js/libs/draco/gltf/draco_wasm_wrapper.js
100755 → 100644

Large diffs are not rendered by default.

112 changes: 35 additions & 77 deletions examples/js/loaders/DRACOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,33 +536,28 @@ THREE.DRACOLoader.DRACOWorker = function () {
// Add index.
if ( geometryType === draco.TRIANGULAR_MESH ) {

// Generate mesh faces.
var numFaces = dracoGeometry.num_faces();
var numIndices = numFaces * 3;
var index = new Uint32Array( numIndices );
var indexArray = new draco.DracoInt32Array();
geometry.index = decodeIndex( draco, decoder, dracoGeometry );

for ( var i = 0; i < numFaces; ++ i ) {

decoder.GetFaceFromMesh( dracoGeometry, i, indexArray );

for ( var j = 0; j < 3; ++ j ) {
}

index[ i * 3 + j ] = indexArray.GetValue( j );
draco.destroy( dracoGeometry );

}
return geometry;

}
}

geometry.index = { array: index, itemSize: 1 };
function decodeIndex( draco, decoder, dracoGeometry ) {

draco.destroy( indexArray );
var numFaces = dracoGeometry.num_faces();
var numIndices = numFaces * 3;
var byteLength = numIndices * 4;

}
var ptr = draco._malloc( byteLength );
decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
var index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
draco._free( ptr );

draco.destroy( dracoGeometry );

return geometry;
return { array: index, itemSize: 1 };

}

Expand All @@ -571,73 +566,36 @@ THREE.DRACOLoader.DRACOWorker = function () {
var numComponents = attribute.num_components();
var numPoints = dracoGeometry.num_points();
var numValues = numPoints * numComponents;
var dracoArray;

var array;

switch ( attributeType ) {

case Float32Array:
dracoArray = new draco.DracoFloat32Array();
decoder.GetAttributeFloatForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Float32Array( numValues );
break;

case Int8Array:
dracoArray = new draco.DracoInt8Array();
decoder.GetAttributeInt8ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int8Array( numValues );
break;

case Int16Array:
dracoArray = new draco.DracoInt16Array();
decoder.GetAttributeInt16ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int16Array( numValues );
break;
var byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
var dataType = getDracoDataType( draco, attributeType );

case Int32Array:
dracoArray = new draco.DracoInt32Array();
decoder.GetAttributeInt32ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int32Array( numValues );
break;

case Uint8Array:
dracoArray = new draco.DracoUInt8Array();
decoder.GetAttributeUInt8ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint8Array( numValues );
break;
var ptr = draco._malloc( byteLength );
decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
var array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
draco._free( ptr );

case Uint16Array:
dracoArray = new draco.DracoUInt16Array();
decoder.GetAttributeUInt16ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint16Array( numValues );
break;

case Uint32Array:
dracoArray = new draco.DracoUInt32Array();
decoder.GetAttributeUInt32ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint32Array( numValues );
break;
return {
name: attributeName,
array: array,
itemSize: numComponents
};

default:
throw new Error( 'THREE.DRACOLoader: Unexpected attribute type.' );
}

}
function getDracoDataType ( draco, attributeType ) {

for ( var i = 0; i < numValues; i ++ ) {
switch ( attributeType ) {

array[ i ] = dracoArray.GetValue( i );
case Float32Array: return draco.DT_FLOAT32;
case Int8Array: return draco.DT_INT8;
case Int16Array: return draco.DT_INT16;
case Int32Array: return draco.DT_INT32;
case Uint8Array: return draco.DT_UINT8;
case Uint16Array: return draco.DT_UINT16;
case Uint32Array: return draco.DT_UINT32;

}

draco.destroy( dracoArray );

return {
name: attributeName,
array: array,
itemSize: numComponents
};

}

};
Expand Down
112 changes: 35 additions & 77 deletions examples/jsm/loaders/DRACOLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,33 +541,28 @@ DRACOLoader.DRACOWorker = function () {
// Add index.
if ( geometryType === draco.TRIANGULAR_MESH ) {

// Generate mesh faces.
var numFaces = dracoGeometry.num_faces();
var numIndices = numFaces * 3;
var index = new Uint32Array( numIndices );
var indexArray = new draco.DracoInt32Array();
geometry.index = decodeIndex( draco, decoder, dracoGeometry );

for ( var i = 0; i < numFaces; ++ i ) {

decoder.GetFaceFromMesh( dracoGeometry, i, indexArray );

for ( var j = 0; j < 3; ++ j ) {
}

index[ i * 3 + j ] = indexArray.GetValue( j );
draco.destroy( dracoGeometry );

}
return geometry;

}
}

geometry.index = { array: index, itemSize: 1 };
function decodeIndex( draco, decoder, dracoGeometry ) {

draco.destroy( indexArray );
var numFaces = dracoGeometry.num_faces();
var numIndices = numFaces * 3;
var byteLength = numIndices * 4;

}
var ptr = draco._malloc( byteLength );
decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
var index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
draco._free( ptr );

draco.destroy( dracoGeometry );

return geometry;
return { array: index, itemSize: 1 };

}

Expand All @@ -576,73 +571,36 @@ DRACOLoader.DRACOWorker = function () {
var numComponents = attribute.num_components();
var numPoints = dracoGeometry.num_points();
var numValues = numPoints * numComponents;
var dracoArray;

var array;

switch ( attributeType ) {

case Float32Array:
dracoArray = new draco.DracoFloat32Array();
decoder.GetAttributeFloatForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Float32Array( numValues );
break;

case Int8Array:
dracoArray = new draco.DracoInt8Array();
decoder.GetAttributeInt8ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int8Array( numValues );
break;

case Int16Array:
dracoArray = new draco.DracoInt16Array();
decoder.GetAttributeInt16ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int16Array( numValues );
break;
var byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
var dataType = getDracoDataType( draco, attributeType );

case Int32Array:
dracoArray = new draco.DracoInt32Array();
decoder.GetAttributeInt32ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Int32Array( numValues );
break;

case Uint8Array:
dracoArray = new draco.DracoUInt8Array();
decoder.GetAttributeUInt8ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint8Array( numValues );
break;
var ptr = draco._malloc( byteLength );
decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
var array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
draco._free( ptr );

case Uint16Array:
dracoArray = new draco.DracoUInt16Array();
decoder.GetAttributeUInt16ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint16Array( numValues );
break;

case Uint32Array:
dracoArray = new draco.DracoUInt32Array();
decoder.GetAttributeUInt32ForAllPoints( dracoGeometry, attribute, dracoArray );
array = new Uint32Array( numValues );
break;
return {
name: attributeName,
array: array,
itemSize: numComponents
};

default:
throw new Error( 'THREE.DRACOLoader: Unexpected attribute type.' );
}

}
function getDracoDataType ( draco, attributeType ) {

for ( var i = 0; i < numValues; i ++ ) {
switch ( attributeType ) {

array[ i ] = dracoArray.GetValue( i );
case Float32Array: return draco.DT_FLOAT32;
case Int8Array: return draco.DT_INT8;
case Int16Array: return draco.DT_INT16;
case Int32Array: return draco.DT_INT32;
case Uint8Array: return draco.DT_UINT8;
case Uint16Array: return draco.DT_UINT16;
case Uint32Array: return draco.DT_UINT32;

}

draco.destroy( dracoArray );

return {
name: attributeName,
array: array,
itemSize: numComponents
};

}

};
Expand Down

0 comments on commit b073104

Please sign in to comment.