|
@@ -104,17 +104,15 @@ class PLYLoader extends Loader {
|
|
|
|
|
|
parse( data ) {
|
|
|
|
|
|
- function parseHeader( data ) {
|
|
|
+ function parseHeader( data, headerLength = 0 ) {
|
|
|
|
|
|
const patternHeader = /^ply([\s\S]*)end_header(\r\n|\r|\n)/;
|
|
|
let headerText = '';
|
|
|
- let headerLength = 0;
|
|
|
const result = patternHeader.exec( data );
|
|
|
|
|
|
if ( result !== null ) {
|
|
|
|
|
|
headerText = result[ 1 ];
|
|
|
- headerLength = new Blob( [ result[ 0 ] ] ).size;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -680,6 +678,9 @@ class PLYLoader extends Loader {
|
|
|
let line = '';
|
|
|
const lines = [];
|
|
|
|
|
|
+ const startLine = new TextDecoder().decode( bytes.subarray( 0, 5 ) );
|
|
|
+ const hasCRNL = /^ply\r\n/.test( startLine );
|
|
|
+
|
|
|
do {
|
|
|
|
|
|
const c = String.fromCharCode( bytes[ i ++ ] );
|
|
@@ -702,7 +703,10 @@ class PLYLoader extends Loader {
|
|
|
|
|
|
} while ( cont && i < bytes.length );
|
|
|
|
|
|
- return lines.join( '\r' ) + '\r';
|
|
|
+ // ascii section using \r\n as line endings
|
|
|
+ if ( hasCRNL === true ) i ++;
|
|
|
+
|
|
|
+ return { headerText: lines.join( '\r' ) + '\r', headerLength: i };
|
|
|
|
|
|
}
|
|
|
|
|
@@ -714,8 +718,8 @@ class PLYLoader extends Loader {
|
|
|
if ( data instanceof ArrayBuffer ) {
|
|
|
|
|
|
const bytes = new Uint8Array( data );
|
|
|
- const headerText = extractHeaderText( bytes );
|
|
|
- const header = parseHeader( headerText );
|
|
|
+ const { headerText, headerLength } = extractHeaderText( bytes );
|
|
|
+ const header = parseHeader( headerText, headerLength );
|
|
|
|
|
|
if ( header.format === 'ascii' ) {
|
|
|
|