Skip to content

Commit

Permalink
Merge pull request #13798 from looeee/FBXLoader_simplify_getData
Browse files Browse the repository at this point in the history
FBXLoader: simplify getData
  • Loading branch information
mrdoob committed Apr 8, 2018
2 parents 566d784 + b612a65 commit d58ec08
Showing 1 changed file with 21 additions and 80 deletions.
101 changes: 21 additions & 80 deletions examples/js/loaders/FBXLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1310,96 +1310,37 @@

}

// Functions use the infoObject and given indices to return value array of geometry.
// Parameters:
// - polygonVertexIndex - Index of vertex in draw order (which index of the index buffer refers to this vertex).
// - polygonIndex - Index of polygon in geometry.
// - vertexIndex - Index of vertex inside vertex buffer (used because some data refers to old index buffer that we don't use anymore).
// - infoObject: can be materialInfo, normalInfo, UVInfo or colorInfo
// Index type:
// - Direct: index is same as polygonVertexIndex
// - IndexToDirect: infoObject has it's own set of indices
var dataArray = [];

var GetData = {

ByPolygonVertex: {

Direct: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var from = ( polygonVertexIndex * infoObject.dataSize );
var to = ( polygonVertexIndex * infoObject.dataSize ) + infoObject.dataSize;

return slice( dataArray, infoObject.buffer, from, to );

},

IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var index = infoObject.indices[ polygonVertexIndex ];
var from = ( index * infoObject.dataSize );
var to = ( index * infoObject.dataSize ) + infoObject.dataSize;

return slice( dataArray, infoObject.buffer, from, to );

}

},

ByPolygon: {

Direct: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var from = polygonIndex * infoObject.dataSize;
var to = polygonIndex * infoObject.dataSize + infoObject.dataSize;

return slice( dataArray, infoObject.buffer, from, to );

},

IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var index = infoObject.indices[ polygonIndex ];
var from = index * infoObject.dataSize;
var to = index * infoObject.dataSize + infoObject.dataSize;

return slice( dataArray, infoObject.buffer, from, to );

}

},

ByVertice: {

Direct: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var from = ( vertexIndex * infoObject.dataSize );
var to = ( vertexIndex * infoObject.dataSize ) + infoObject.dataSize;

return slice( dataArray, infoObject.buffer, from, to );

}

},

AllSame: {

IndexToDirect: function ( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {

var from = infoObject.indices[ 0 ] * infoObject.dataSize;
var to = infoObject.indices[ 0 ] * infoObject.dataSize + infoObject.dataSize;
var index;

return slice( dataArray, infoObject.buffer, from, to );
switch ( infoObject.mappingType ) {

}
case 'ByPolygonVertex' :
index = polygonVertexIndex;
break;
case 'ByPolygon' :
index = polygonIndex;
break;
case 'ByVertice' :
index = vertexIndex;
break;
case 'AllSame' :
index = infoObject.indices[ 0 ];
break;
default :
console.warn( 'THREE.FBXLoader: unknown attribute mapping type ' + infoObject.mappingType );

}

};
if ( infoObject.referenceType === 'IndexToDirect' ) index = infoObject.indices[ index ];

function getData( polygonVertexIndex, polygonIndex, vertexIndex, infoObject ) {
var from = index * infoObject.dataSize;
var to = from + infoObject.dataSize;

return GetData[ infoObject.mappingType ][ infoObject.referenceType ]( polygonVertexIndex, polygonIndex, vertexIndex, infoObject );
return slice( dataArray, infoObject.buffer, from, to );

}

Expand Down

0 comments on commit d58ec08

Please sign in to comment.