@@ -36,8 +36,7 @@ THREE.PLYLoader.prototype = {
3636
3737 request . addEventListener ( 'load' , function ( event ) {
3838
39- var geometry ;
40- geometry = scope . parse ( event . target . response ) ;
39+ var geometry = scope . parse ( event . target . response ) ;
4140
4241 scope . dispatchEvent ( { type : 'load' , content : geometry } ) ;
4342
@@ -70,7 +69,7 @@ THREE.PLYLoader.prototype = {
7069 for ( var i = 0 ; i < buf . byteLength ; i ++ ) {
7170 str += String . fromCharCode ( array_buffer [ i ] ) ; // implicitly assumes little-endian
7271 }
73-
72+
7473 return str ;
7574
7675 } ,
@@ -79,23 +78,28 @@ THREE.PLYLoader.prototype = {
7978
8079 // currently only supports ASCII encoded files.
8180 return true ;
82-
83- } ,
8481
85- parse : function ( buf ) {
82+ } ,
83+
84+ parse : function ( data ) {
85+
86+ if ( data instanceof ArrayBuffer ) {
87+
88+ return this . isASCII ( data )
89+ ? this . parseASCII ( this . bin2str ( data ) )
90+ : this . parseBinary ( data ) ;
8691
87- if ( this . isASCII ( buf ) ) {
88- var str = this . bin2str ( buf ) ;
89- return this . parseASCII ( str ) ;
9092 } else {
91- return this . parseBinary ( buf ) ;
93+
94+ return this . parseASCII ( data ) ;
95+
9296 }
9397
94- } ,
98+ } ,
9599
96100 parseASCII : function ( data ) {
97101
98- // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
102+ // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
99103
100104 var geometry = new THREE . Geometry ( ) ;
101105
@@ -106,13 +110,13 @@ THREE.PLYLoader.prototype = {
106110 if ( ( result = patternHeader . exec ( data ) ) != null ) {
107111 header = result [ 1 ] ;
108112 }
109-
113+
110114 var patternBody = / e n d _ h e a d e r ( [ \s \S ] * ) $ / ;
111115 var body = "" ;
112116 if ( ( result = patternBody . exec ( data ) ) != null ) {
113117 body = result [ 1 ] ;
114118 }
115-
119+
116120 var patternVertexCount = / e l e m e n t [ \s ] + v e r t e x [ \s ] + ( \d + ) / g;
117121 var vertexCount = 0 ;
118122 if ( ( result = patternVertexCount . exec ( header ) ) != null ) {
@@ -124,9 +128,9 @@ THREE.PLYLoader.prototype = {
124128 if ( ( result = patternFaceCount . exec ( header ) ) != null ) {
125129 faceCount = parseInt ( result [ 1 ] ) ;
126130 }
127-
131+
128132 if ( vertexCount != 0 && faceCount != 0 ) {
129- // Vertex
133+ // Vertex
130134 // assume x y z
131135 var patternVertex = / ( [ - + ] ? [ 0 - 9 ] + \. ? [ 0 - 9 ] * ( [ e E ] [ - + ] ? [ 0 - 9 ] + ) ? ) + [ \s ] + ( [ - + ] ? [ 0 - 9 ] * \. ? [ 0 - 9 ] + ( [ e E ] [ - + ] ? [ 0 - 9 ] + ) ? ) + [ \s ] + ( [ - + ] ? [ 0 - 9 ] * \. ? [ 0 - 9 ] + ( [ e E ] [ - + ] ? [ 0 - 9 ] + ) ? ) + / g;
132136 for ( var i = 0 ; i < vertexCount ; i ++ ) {
@@ -137,7 +141,7 @@ THREE.PLYLoader.prototype = {
137141 return geometry ;
138142 }
139143 }
140-
144+
141145 // Face
142146 // assume 3 index0 index1 index2
143147 var patternFace = / 3 [ \s ] + ( [ - + ] ? [ 0 - 9 ] + ) [ \s ] + ( [ - + ] ? [ 0 - 9 ] + ) [ \s ] + ( [ - + ] ? [ 0 - 9 ] + ) / g;
@@ -149,7 +153,7 @@ THREE.PLYLoader.prototype = {
149153 return geometry ;
150154 }
151155 }
152-
156+
153157 } else {
154158 console . error ( 'Header error: vertexCount(' + vertexCount + '), faceCount(' + faceCount + ').' ) ;
155159 }
@@ -165,7 +169,7 @@ THREE.PLYLoader.prototype = {
165169
166170 // not supported yet
167171 console . error ( 'Not supported yet.' ) ;
168-
172+
169173 }
170174
171175
0 commit comments