Skip to content

Commit 651c3cd

Browse files
authored
Merge pull request #14793 from gkjohnson/vrml-scope-fix
Fix the VRMLLoader `this` scope.
2 parents a954381 + 770b429 commit 651c3cd

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

examples/js/loaders/VRMLLoader.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ THREE.VRMLLoader.prototype = {
5050

5151
parse: function ( data ) {
5252

53+
var scope = this;
5354
var texturePath = this.texturePath || '';
5455

5556
var textureLoader = new THREE.TextureLoader( this.manager );
@@ -204,34 +205,34 @@ THREE.VRMLLoader.prototype = {
204205

205206
case 'skyAngle':
206207
case 'groundAngle':
207-
this.recordingFieldname = fieldName;
208-
this.isRecordingAngles = true;
209-
this.angles = [];
208+
scope.recordingFieldname = fieldName;
209+
scope.isRecordingAngles = true;
210+
scope.angles = [];
210211
break;
211212

212213
case 'skyColor':
213214
case 'groundColor':
214-
this.recordingFieldname = fieldName;
215-
this.isRecordingColors = true;
216-
this.colors = [];
215+
scope.recordingFieldname = fieldName;
216+
scope.isRecordingColors = true;
217+
scope.colors = [];
217218
break;
218219

219220
case 'point':
220-
this.recordingFieldname = fieldName;
221-
this.isRecordingPoints = true;
222-
this.points = [];
221+
scope.recordingFieldname = fieldName;
222+
scope.isRecordingPoints = true;
223+
scope.points = [];
223224
break;
224225

225226
case 'coordIndex':
226227
case 'texCoordIndex':
227-
this.recordingFieldname = fieldName;
228-
this.isRecordingFaces = true;
229-
this.indexes = [];
228+
scope.recordingFieldname = fieldName;
229+
scope.isRecordingFaces = true;
230+
scope.indexes = [];
230231
break;
231232

232233
}
233234

234-
if ( this.isRecordingFaces ) {
235+
if ( scope.isRecordingFaces ) {
235236

236237
// the parts hold the indexes as strings
237238
if ( parts.length > 0 ) {
@@ -250,7 +251,7 @@ THREE.VRMLLoader.prototype = {
250251

251252
if ( index.length > 0 ) {
252253

253-
this.indexes.push( index );
254+
scope.indexes.push( index );
254255

255256
}
256257

@@ -272,19 +273,19 @@ THREE.VRMLLoader.prototype = {
272273

273274
if ( index.length > 0 ) {
274275

275-
this.indexes.push( index );
276+
scope.indexes.push( index );
276277

277278
}
278279

279280
// start new one
280281
index = [];
281282

282-
this.isRecordingFaces = false;
283-
node[ this.recordingFieldname ] = this.indexes;
283+
scope.isRecordingFaces = false;
284+
node[ scope.recordingFieldname ] = scope.indexes;
284285

285286
}
286287

287-
} else if ( this.isRecordingPoints ) {
288+
} else if ( scope.isRecordingPoints ) {
288289

289290
if ( node.nodeType == 'Coordinate' ) {
290291

@@ -296,7 +297,7 @@ THREE.VRMLLoader.prototype = {
296297
z: parseFloat( parts[ 3 ] )
297298
};
298299

299-
this.points.push( point );
300+
scope.points.push( point );
300301

301302
}
302303

@@ -311,7 +312,7 @@ THREE.VRMLLoader.prototype = {
311312
y: parseFloat( parts[ 2 ] )
312313
};
313314

314-
this.points.push( point );
315+
scope.points.push( point );
315316

316317
}
317318

@@ -320,12 +321,12 @@ THREE.VRMLLoader.prototype = {
320321
// end
321322
if ( /]/.exec( line ) ) {
322323

323-
this.isRecordingPoints = false;
324-
node.points = this.points;
324+
scope.isRecordingPoints = false;
325+
node.points = scope.points;
325326

326327
}
327328

328-
} else if ( this.isRecordingAngles ) {
329+
} else if ( scope.isRecordingAngles ) {
329330

330331
// the parts hold the angles as strings
331332
if ( parts.length > 0 ) {
@@ -339,7 +340,7 @@ THREE.VRMLLoader.prototype = {
339340

340341
}
341342

342-
this.angles.push( parseFloat( parts[ ind ] ) );
343+
scope.angles.push( parseFloat( parts[ ind ] ) );
343344

344345
}
345346

@@ -348,12 +349,12 @@ THREE.VRMLLoader.prototype = {
348349
// end
349350
if ( /]/.exec( line ) ) {
350351

351-
this.isRecordingAngles = false;
352-
node[ this.recordingFieldname ] = this.angles;
352+
scope.isRecordingAngles = false;
353+
node[ scope.recordingFieldname ] = scope.angles;
353354

354355
}
355356

356-
} else if ( this.isRecordingColors ) {
357+
} else if ( scope.isRecordingColors ) {
357358

358359
while ( null !== ( parts = float3_pattern.exec( line ) ) ) {
359360

@@ -363,15 +364,15 @@ THREE.VRMLLoader.prototype = {
363364
b: parseFloat( parts[ 3 ] )
364365
};
365366

366-
this.colors.push( color );
367+
scope.colors.push( color );
367368

368369
}
369370

370371
// end
371372
if ( /]/.exec( line ) ) {
372373

373-
this.isRecordingColors = false;
374-
node[ this.recordingFieldname ] = this.colors;
374+
scope.isRecordingColors = false;
375+
node[ scope.recordingFieldname ] = scope.colors;
375376

376377
}
377378

0 commit comments

Comments
 (0)