private void readBinary(final LittleEndianDataInputStream dis) throws IOException {
  RajLog.i("StlPaser: Reading Binary");
  dis.skip(80);
  int facetCount=dis.readInt();
  float[] verticesArr=new float[facetCount * 9];
  float[] normalsArr=new float[facetCount * 9];
  int[] indicesArr=new int[facetCount * 3];
  float[] tempNorms=new float[3];
  int vertPos=0, normPos=0;
  for (int i=0; i < indicesArr.length; i++)   indicesArr[i]=i;
  while (dis.available() > 0) {
    for (int j=0; j < 3; j++) {
      tempNorms[j]=dis.readFloat();
      if (Float.isNaN(tempNorms[j]) || Float.isInfinite(tempNorms[j])) {
        RajLog.w("STL contains bad normals of NaN or Infinite!");
        tempNorms[0]=0;
        tempNorms[1]=0;
        tempNorms[2]=0;
        break;
      }
    }
    for (int j=0; j < 3; j++) {
      normalsArr[normPos++]=tempNorms[0];
      normalsArr[normPos++]=tempNorms[1];
      normalsArr[normPos++]=tempNorms[2];
    }
    for (int j=0; j < 9; j++)     verticesArr[vertPos++]=dis.readFloat();
    dis.skip(2);
  }
  mRootObject.setData(verticesArr,normalsArr,null,null,indicesArr,false);
}

private void readBinary ( final LittleEndianDataInputStream dis ) throws IOException { RajLog . i ( "StlPaser: Reading Binary" ) ; dis . skip ( 80 ) ; int facetCount = dis . readInt ( ) ; float [ ] verticesArr = new float [ facetCount * 9 ] ; float [ ] normalsArr = new float [ facetCount * 9 ] ; int [ ] indicesArr = new int [ facetCount * 3 ] ; float [ ] tempNorms = new float [ 3 ] ; int vertPos = 0 , normPos = 0 ; for ( int i = 0 ; i < indicesArr . length ; i ++ ) indicesArr [ i ] = i ; while ( dis . available ( ) > 0 ) { for ( int j = 0 ; j < 3 ; j ++ ) { tempNorms [ j ] = dis . readFloat ( ) ; if ( Float . isNaN ( tempNorms [ j ] ) || Float . isInfinite ( tempNorms [ j ] ) ) { RajLog . w ( "STL contains bad normals of NaN or Infinite!" ) ; tempNorms [ 0 ] = 0 ; tempNorms [ 1 ] = 0 ; tempNorms [ 2 ] = 0 ; break ; } } for ( int j = 0 ; j < 3 ; j ++ ) { normalsArr [ normPos ++ ] = tempNorms [ 0 ] ; normalsArr [ normPos ++ ] = tempNorms [ 1 ] ; normalsArr [ normPos ++ ] = tempNorms [ 2 ] ; } for ( int j = 0 ; j < 9 ; j ++ ) verticesArr [ vertPos ++ ] = dis . readFloat ( ) ; dis . skip ( 2 ) ; } mRootObject . setData ( verticesArr , normalsArr , null , null , indicesArr , false ) ; }
read stream as binary stl . this is significantly faster than ascii parsing . additionally binary files are much more compressed allowing smaller file sizes for larger models compared to ascii .
