|
@@ -61,19 +61,19 @@ THREE.PLYLoader.prototype = {
|
|
|
|
|
|
parse: function ( data ) {
|
|
parse: function ( data ) {
|
|
|
|
|
|
- function isASCII( data ) {
|
|
|
|
|
|
+ function bin2str( buf ) {
|
|
|
|
|
|
- var header = parseHeader( bin2str( data ) );
|
|
|
|
- return header.format === 'ascii';
|
|
|
|
|
|
+ var array_buffer = new Uint8Array( buf );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( window.TextDecoder !== undefined ) {
|
|
|
|
|
|
- function bin2str( buf ) {
|
|
|
|
|
|
+ return new TextDecoder().decode( array_buffer );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- var array_buffer = new Uint8Array( buf );
|
|
|
|
var str = '';
|
|
var str = '';
|
|
|
|
|
|
- for ( var i = 0; i < buf.byteLength; i ++ ) {
|
|
|
|
|
|
+ for ( var i = 0, il = buf.byteLength; i < il; i ++ ) {
|
|
|
|
|
|
str += String.fromCharCode( array_buffer[ i ] ); // implicitly assumes little-endian
|
|
str += String.fromCharCode( array_buffer[ i ] ); // implicitly assumes little-endian
|
|
|
|
|
|
@@ -249,7 +249,7 @@ THREE.PLYLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function parseASCII( data ) {
|
|
|
|
|
|
+ function parseASCII( data, header ) {
|
|
|
|
|
|
// PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
|
|
// PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
|
|
|
|
|
|
@@ -263,8 +263,6 @@ THREE.PLYLoader.prototype = {
|
|
|
|
|
|
var result;
|
|
var result;
|
|
|
|
|
|
- var header = parseHeader( data );
|
|
|
|
-
|
|
|
|
var patternBody = /end_header\s([\s\S]*)$/;
|
|
var patternBody = /end_header\s([\s\S]*)$/;
|
|
var body = '';
|
|
var body = '';
|
|
if ( ( result = patternBody.exec( data ) ) !== null ) {
|
|
if ( ( result = patternBody.exec( data ) ) !== null ) {
|
|
@@ -446,7 +444,7 @@ THREE.PLYLoader.prototype = {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- function parseBinary( data ) {
|
|
|
|
|
|
+ function parseBinary( data, header ) {
|
|
|
|
|
|
var buffer = {
|
|
var buffer = {
|
|
indices : [],
|
|
indices : [],
|
|
@@ -456,7 +454,6 @@ THREE.PLYLoader.prototype = {
|
|
colors : []
|
|
colors : []
|
|
};
|
|
};
|
|
|
|
|
|
- var header = parseHeader( bin2str( data ) );
|
|
|
|
var little_endian = ( header.format === 'binary_little_endian' );
|
|
var little_endian = ( header.format === 'binary_little_endian' );
|
|
var body = new DataView( data, header.headerLength );
|
|
var body = new DataView( data, header.headerLength );
|
|
var result, loc = 0;
|
|
var result, loc = 0;
|
|
@@ -486,11 +483,14 @@ THREE.PLYLoader.prototype = {
|
|
|
|
|
|
if ( data instanceof ArrayBuffer ) {
|
|
if ( data instanceof ArrayBuffer ) {
|
|
|
|
|
|
- geometry = isASCII( data ) ? parseASCII( bin2str( data ) ) : parseBinary( data );
|
|
|
|
|
|
+ var text = bin2str( data );
|
|
|
|
+ var header = parseHeader( text );
|
|
|
|
+
|
|
|
|
+ geometry = header.format === 'ascii' ? parseASCII( text, header ) : parseBinary( data, header );
|
|
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- geometry = parseASCII( data );
|
|
|
|
|
|
+ geometry = parseASCII( data, parseHeader( data ) );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|