Browse Source

Core: Eagerly instantiate module scope variables.

Mugen87 6 years ago
parent
commit
ec43642749

+ 32 - 44
src/animation/PropertyBinding.js

@@ -10,9 +10,39 @@
 
 
 // Characters [].:/ are reserved for track binding syntax.
 // Characters [].:/ are reserved for track binding syntax.
 var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
 var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
+var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
 
 
-var _reservedRe;
-var _trackRe, _supportedObjectNames;
+// Attempts to allow node names from any language. ES5's `\w` regexp matches
+// only latin characters, and the unicode \p{L} is not yet supported. So
+// instead, we exclude reserved characters and match everything else.
+var _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
+var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
+
+// Parent directories, delimited by '/' or ':'. Currently unused, but must
+// be matched to parse the rest of the track name.
+var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
+
+// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
+var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
+
+// Object on target node, and accessor. May not contain reserved
+// characters. Accessor may contain any character except closing bracket.
+var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
+
+// Property and accessor. May not contain reserved characters. Accessor may
+// contain any non-bracket characters.
+var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
+
+var _trackRe = new RegExp( ''
+	+ '^'
+	+ _directoryRe
+	+ _nodeRe
+	+ _objectRe
+	+ _propertyRe
+	+ '$'
+);
+
+var _supportedObjectNames = [ 'material', 'materials', 'bones' ];
 
 
 function Composite( targetGroup, path, optionalParsedPath ) {
 function Composite( targetGroup, path, optionalParsedPath ) {
 
 
@@ -114,54 +144,12 @@ Object.assign( PropertyBinding, {
 	 */
 	 */
 	sanitizeNodeName: function ( name ) {
 	sanitizeNodeName: function ( name ) {
 
 
-		if ( _reservedRe === undefined ) {
-
-			_reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
-
-		}
-
 		return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
 		return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
 
 
 	},
 	},
 
 
 	parseTrackName: function ( trackName ) {
 	parseTrackName: function ( trackName ) {
 
 
-		if ( _supportedObjectNames === undefined ) {
-
-			// Attempts to allow node names from any language. ES5's `\w` regexp matches
-			// only latin characters, and the unicode \p{L} is not yet supported. So
-			// instead, we exclude reserved characters and match everything else.
-			var wordChar = '[^' + _RESERVED_CHARS_RE + ']';
-			var wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
-
-			// Parent directories, delimited by '/' or ':'. Currently unused, but must
-			// be matched to parse the rest of the track name.
-			var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
-
-			// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
-			var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
-
-			// Object on target node, and accessor. May not contain reserved
-			// characters. Accessor may contain any character except closing bracket.
-			var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
-
-			// Property and accessor. May not contain reserved characters. Accessor may
-			// contain any non-bracket characters.
-			var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
-
-			_trackRe = new RegExp( ''
-				+ '^'
-				+ directoryRe
-				+ nodeRe
-				+ objectRe
-				+ propertyRe
-				+ '$'
-			);
-
-			_supportedObjectNames = [ 'material', 'materials', 'bones' ];
-
-		}
-
 		var matches = _trackRe.exec( trackName );
 		var matches = _trackRe.exec( trackName );
 
 
 		if ( ! matches ) {
 		if ( ! matches ) {

+ 4 - 11
src/audio/AudioListener.js

@@ -8,8 +8,10 @@ import { Clock } from '../core/Clock.js';
 import { Object3D } from '../core/Object3D.js';
 import { Object3D } from '../core/Object3D.js';
 import { AudioContext } from './AudioContext.js';
 import { AudioContext } from './AudioContext.js';
 
 
-var _position, _quaternion, _scale;
-var _orientation;
+var _position = new Vector3();
+var _quaternion = new Quaternion();
+var _scale = new Vector3();
+var _orientation = new Vector3();
 
 
 function AudioListener() {
 function AudioListener() {
 
 
@@ -102,15 +104,6 @@ AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 		Object3D.prototype.updateMatrixWorld.call( this, force );
 		Object3D.prototype.updateMatrixWorld.call( this, force );
 
 
-		if ( _position === undefined ) {
-
-			_position = new Vector3();
-			_quaternion = new Quaternion();
-			_scale = new Vector3();
-			_orientation = new Vector3();
-
-		}
-
 		var listener = this.context.listener;
 		var listener = this.context.listener;
 		var up = this.up;
 		var up = this.up;
 
 

+ 4 - 11
src/audio/PositionalAudio.js

@@ -7,8 +7,10 @@ import { Quaternion } from '../math/Quaternion.js';
 import { Audio } from './Audio.js';
 import { Audio } from './Audio.js';
 import { Object3D } from '../core/Object3D.js';
 import { Object3D } from '../core/Object3D.js';
 
 
-var _position, _quaternion, _scale;
-var _orientation;
+var _position = new Vector3();
+var _quaternion = new Quaternion();
+var _scale = new Vector3();
+var _orientation = new Vector3();
 
 
 function PositionalAudio( listener ) {
 function PositionalAudio( listener ) {
 
 
@@ -100,15 +102,6 @@ PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
 
 
 		Object3D.prototype.updateMatrixWorld.call( this, force );
 		Object3D.prototype.updateMatrixWorld.call( this, force );
 
 
-		if ( _position === undefined ) {
-
-			_position = new Vector3();
-			_quaternion = new Quaternion();
-			_scale = new Vector3();
-			_orientation = new Vector3();
-
-		}
-
 		if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
 		if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
 
 
 		this.matrixWorld.decompose( _position, _quaternion, _scale );
 		this.matrixWorld.decompose( _position, _quaternion, _scale );

+ 2 - 8
src/cameras/StereoCamera.js

@@ -2,7 +2,8 @@ import { Matrix4 } from '../math/Matrix4.js';
 import { _Math } from '../math/Math.js';
 import { _Math } from '../math/Math.js';
 import { PerspectiveCamera } from './PerspectiveCamera.js';
 import { PerspectiveCamera } from './PerspectiveCamera.js';
 
 
-var _eyeRight, _eyeLeft;
+var _eyeRight = new Matrix4();
+var _eyeLeft = new Matrix4();
 
 
 /**
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
@@ -40,13 +41,6 @@ Object.assign( StereoCamera.prototype, {
 
 
 	update: function ( camera ) {
 	update: function ( camera ) {
 
 
-		if ( _eyeRight === undefined ) {
-
-			_eyeRight = new Matrix4();
-			_eyeLeft = new Matrix4();
-
-		}
-
 		var cache = this._cache;
 		var cache = this._cache;
 
 
 		var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
 		var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||

+ 7 - 33
src/core/BufferGeometry.js

@@ -16,9 +16,13 @@ import { arrayMax } from '../utils.js';
  */
  */
 
 
 var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
 var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
-var _m1, _obj, _offset;
-var _box, _boxMorphTargets;
-var _vector;
+
+var _m1 = new Matrix4();
+var _obj = new Object3D();
+var _offset = new Vector3();
+var _box = new Box3();
+var _boxMorphTargets = new Box3();
+var _vector = new Vector3();
 
 
 function BufferGeometry() {
 function BufferGeometry() {
 
 
@@ -189,8 +193,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 		// rotate geometry around world x-axis
 		// rotate geometry around world x-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationX( angle );
 		_m1.makeRotationX( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -203,8 +205,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 		// rotate geometry around world y-axis
 		// rotate geometry around world y-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationY( angle );
 		_m1.makeRotationY( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -217,8 +217,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 		// rotate geometry around world z-axis
 		// rotate geometry around world z-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationZ( angle );
 		_m1.makeRotationZ( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -231,8 +229,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 		// translate geometry
 		// translate geometry
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeTranslation( x, y, z );
 		_m1.makeTranslation( x, y, z );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -245,8 +241,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 		// scale geometry
 		// scale geometry
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeScale( x, y, z );
 		_m1.makeScale( x, y, z );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -257,8 +251,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 	lookAt: function ( vector ) {
 	lookAt: function ( vector ) {
 
 
-		if ( _obj === undefined ) _obj = new Object3D();
-
 		_obj.lookAt( vector );
 		_obj.lookAt( vector );
 
 
 		_obj.updateMatrix();
 		_obj.updateMatrix();
@@ -271,8 +263,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 	center: function () {
 	center: function () {
 
 
-		if ( _offset === undefined ) _offset = new Vector3();
-
 		this.computeBoundingBox();
 		this.computeBoundingBox();
 
 
 		this.boundingBox.getCenter( _offset ).negate();
 		this.boundingBox.getCenter( _offset ).negate();
@@ -578,12 +568,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 	computeBoundingBox: function () {
 	computeBoundingBox: function () {
 
 
-		if ( _box === undefined ) {
-
-			_box = new Box3();
-
-		}
-
 		if ( this.boundingBox === null ) {
 		if ( this.boundingBox === null ) {
 
 
 			this.boundingBox = new Box3();
 			this.boundingBox = new Box3();
@@ -629,14 +613,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 	computeBoundingSphere: function () {
 	computeBoundingSphere: function () {
 
 
-		if ( _boxMorphTargets === undefined ) {
-
-			_box = new Box3();
-			_vector = new Vector3();
-			_boxMorphTargets = new Box3();
-
-		}
-
 		if ( this.boundingSphere === null ) {
 		if ( this.boundingSphere === null ) {
 
 
 			this.boundingSphere = new Sphere();
 			this.boundingSphere = new Sphere();
@@ -877,8 +853,6 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 
 	normalizeNormals: function () {
 	normalizeNormals: function () {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var normals = this.attributes.normal;
 		var normals = this.attributes.normal;
 
 
 		for ( var i = 0, il = normals.count; i < il; i ++ ) {
 		for ( var i = 0, il = normals.count; i < il; i ++ ) {

+ 3 - 15
src/core/Geometry.js

@@ -20,7 +20,9 @@ import { _Math } from '../math/Math.js';
  */
  */
 
 
 var _geometryId = 0; // Geometry uses even numbers as Id
 var _geometryId = 0; // Geometry uses even numbers as Id
-var _m1, _obj, _offset;
+var _m1 = new Matrix4();
+var _obj = new Object3D();
+var _offset = new Vector3();
 
 
 function Geometry() {
 function Geometry() {
 
 
@@ -112,8 +114,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// rotate geometry around world x-axis
 		// rotate geometry around world x-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationX( angle );
 		_m1.makeRotationX( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -126,8 +126,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// rotate geometry around world y-axis
 		// rotate geometry around world y-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationY( angle );
 		_m1.makeRotationY( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -140,8 +138,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// rotate geometry around world z-axis
 		// rotate geometry around world z-axis
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeRotationZ( angle );
 		_m1.makeRotationZ( angle );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -154,8 +150,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// translate geometry
 		// translate geometry
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeTranslation( x, y, z );
 		_m1.makeTranslation( x, y, z );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -168,8 +162,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// scale geometry
 		// scale geometry
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		_m1.makeScale( x, y, z );
 		_m1.makeScale( x, y, z );
 
 
 		this.applyMatrix( _m1 );
 		this.applyMatrix( _m1 );
@@ -180,8 +172,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	lookAt: function ( vector ) {
 	lookAt: function ( vector ) {
 
 
-		if ( _obj === undefined ) _obj = new Object3D();
-
 		_obj.lookAt( vector );
 		_obj.lookAt( vector );
 
 
 		_obj.updateMatrix();
 		_obj.updateMatrix();
@@ -327,8 +317,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	center: function () {
 	center: function () {
 
 
-		if ( _offset === undefined ) _offset = new Vector3();
-
 		this.computeBoundingBox();
 		this.computeBoundingBox();
 
 
 		this.boundingBox.getCenter( _offset ).negate();
 		this.boundingBox.getCenter( _offset ).negate();

+ 14 - 47
src/core/Object3D.js

@@ -17,9 +17,20 @@ import { TrianglesDrawMode } from '../constants.js';
  */
  */
 
 
 var _object3DId = 0;
 var _object3DId = 0;
-var _m1, _q1, _v1;
-var _xAxis, _yAxis, _zAxis;
-var _target, _position, _scale, _quaternion;
+
+var _v1 = new Vector3();
+var _q1 = new Quaternion();
+var _m1 = new Matrix4();
+var _target = new Vector3();
+
+var _position = new Vector3();
+var _scale = new Vector3();
+var _quaternion = new Quaternion();
+
+var _xAxis = new Vector3( 1, 0, 0 );
+var _yAxis = new Vector3( 0, 1, 0 );
+var _zAxis = new Vector3( 0, 0, 1 );
+
 var _addedEvent = { type: 'added' };
 var _addedEvent = { type: 'added' };
 var _removedEvent = { type: 'removed' };
 var _removedEvent = { type: 'removed' };
 
 
@@ -170,8 +181,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 		// rotate object on axis in object space
 		// rotate object on axis in object space
 		// axis is assumed to be normalized
 		// axis is assumed to be normalized
 
 
-		if ( _q1 === undefined ) _q1 = new Quaternion();
-
 		_q1.setFromAxisAngle( axis, angle );
 		_q1.setFromAxisAngle( axis, angle );
 
 
 		this.quaternion.multiply( _q1 );
 		this.quaternion.multiply( _q1 );
@@ -186,8 +195,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 		// axis is assumed to be normalized
 		// axis is assumed to be normalized
 		// method assumes no rotated parent
 		// method assumes no rotated parent
 
 
-		if ( _q1 === undefined ) _q1 = new Quaternion();
-
 		_q1.setFromAxisAngle( axis, angle );
 		_q1.setFromAxisAngle( axis, angle );
 
 
 		this.quaternion.premultiply( _q1 );
 		this.quaternion.premultiply( _q1 );
@@ -198,24 +205,18 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	rotateX: function ( angle ) {
 	rotateX: function ( angle ) {
 
 
-		if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
-
 		return this.rotateOnAxis( _xAxis, angle );
 		return this.rotateOnAxis( _xAxis, angle );
 
 
 	},
 	},
 
 
 	rotateY: function ( angle ) {
 	rotateY: function ( angle ) {
 
 
-		if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
-
 		return this.rotateOnAxis( _yAxis, angle );
 		return this.rotateOnAxis( _yAxis, angle );
 
 
 	},
 	},
 
 
 	rotateZ: function ( angle ) {
 	rotateZ: function ( angle ) {
 
 
-		if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
-
 		return this.rotateOnAxis( _zAxis, angle );
 		return this.rotateOnAxis( _zAxis, angle );
 
 
 	},
 	},
@@ -225,8 +226,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 		// translate object by distance along axis in object space
 		// translate object by distance along axis in object space
 		// axis is assumed to be normalized
 		// axis is assumed to be normalized
 
 
-		if ( _v1 === undefined ) _v1 = new Vector3();
-
 		_v1.copy( axis ).applyQuaternion( this.quaternion );
 		_v1.copy( axis ).applyQuaternion( this.quaternion );
 
 
 		this.position.add( _v1.multiplyScalar( distance ) );
 		this.position.add( _v1.multiplyScalar( distance ) );
@@ -237,24 +236,18 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	translateX: function ( distance ) {
 	translateX: function ( distance ) {
 
 
-		if ( _xAxis === undefined ) _xAxis = new Vector3( 1, 0, 0 );
-
 		return this.translateOnAxis( _xAxis, distance );
 		return this.translateOnAxis( _xAxis, distance );
 
 
 	},
 	},
 
 
 	translateY: function ( distance ) {
 	translateY: function ( distance ) {
 
 
-		if ( _yAxis === undefined ) _yAxis = new Vector3( 0, 1, 0 );
-
 		return this.translateOnAxis( _yAxis, distance );
 		return this.translateOnAxis( _yAxis, distance );
 
 
 	},
 	},
 
 
 	translateZ: function ( distance ) {
 	translateZ: function ( distance ) {
 
 
-		if ( _zAxis === undefined ) _zAxis = new Vector3( 0, 0, 1 );
-
 		return this.translateOnAxis( _zAxis, distance );
 		return this.translateOnAxis( _zAxis, distance );
 
 
 	},
 	},
@@ -267,8 +260,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	worldToLocal: function ( vector ) {
 	worldToLocal: function ( vector ) {
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		return vector.applyMatrix4( _m1.getInverse( this.matrixWorld ) );
 		return vector.applyMatrix4( _m1.getInverse( this.matrixWorld ) );
 
 
 	},
 	},
@@ -277,15 +268,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// This method does not support objects having non-uniformly-scaled parent(s)
 		// This method does not support objects having non-uniformly-scaled parent(s)
 
 
-		if ( _target === undefined ) {
-
-			_q1 = new Quaternion();
-			_m1 = new Matrix4();
-			_target = new Vector3();
-			_position = new Vector3();
-
-		}
-
 		if ( x.isVector3 ) {
 		if ( x.isVector3 ) {
 
 
 			_target.copy( x );
 			_target.copy( x );
@@ -401,8 +383,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 		// adds object as a child of this, while maintaining the object's world transform
 		// adds object as a child of this, while maintaining the object's world transform
 
 
-		if ( _m1 === undefined ) _m1 = new Matrix4();
-
 		this.updateWorldMatrix( true, false );
 		this.updateWorldMatrix( true, false );
 
 
 		_m1.getInverse( this.matrixWorld );
 		_m1.getInverse( this.matrixWorld );
@@ -475,13 +455,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	getWorldQuaternion: function ( target ) {
 	getWorldQuaternion: function ( target ) {
 
 
-		if ( _scale === undefined ) {
-
-			_position = new Vector3();
-			_scale = new Vector3();
-
-		}
-
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 
 			console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
 			console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
@@ -499,12 +472,6 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	getWorldScale: function ( target ) {
 	getWorldScale: function ( target ) {
 
 
-		if ( _quaternion === undefined ) {
-
-			_position = new Vector3();
-			_quaternion = new Quaternion();
-
-		}
 
 
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 

+ 7 - 14
src/helpers/ArrowHelper.js

@@ -24,8 +24,13 @@ import { Mesh } from '../objects/Mesh.js';
 import { Line } from '../objects/Line.js';
 import { Line } from '../objects/Line.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Vector3 } from '../math/Vector3.js';
 
 
-var _axis;
-var _lineGeometry, _coneGeometry;
+var _axis = new Vector3();
+
+var _lineGeometry = new BufferGeometry();
+_lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
+
+var _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
+_coneGeometry.translate( 0, - 0.5, 0 );
 
 
 function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 
 
@@ -40,16 +45,6 @@ function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 	if ( headLength === undefined ) headLength = 0.2 * length;
 	if ( headLength === undefined ) headLength = 0.2 * length;
 	if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 	if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 
 
-	if ( _lineGeometry === undefined ) {
-
-		_lineGeometry = new BufferGeometry();
-		_lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
-
-		_coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
-		_coneGeometry.translate( 0, - 0.5, 0 );
-
-	}
-
 	this.position.copy( origin );
 	this.position.copy( origin );
 
 
 	this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
 	this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );
@@ -70,8 +65,6 @@ ArrowHelper.prototype.constructor = ArrowHelper;
 
 
 ArrowHelper.prototype.setDirection = function ( dir ) {
 ArrowHelper.prototype.setDirection = function ( dir ) {
 
 
-	if ( _axis === undefined ) _axis = new Vector3();
-
 	// dir is assumed to be normalized
 	// dir is assumed to be normalized
 
 
 	if ( dir.y > 0.99999 ) {
 	if ( dir.y > 0.99999 ) {

+ 1 - 3
src/helpers/BoxHelper.js

@@ -9,7 +9,7 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
 
-var _box;
+var _box = new Box3();
 
 
 function BoxHelper( object, color ) {
 function BoxHelper( object, color ) {
 
 
@@ -37,8 +37,6 @@ BoxHelper.prototype.constructor = BoxHelper;
 
 
 BoxHelper.prototype.update = function ( object ) {
 BoxHelper.prototype.update = function ( object ) {
 
 
-	if ( _box === undefined ) _box = new Box3();
-
 	if ( object !== undefined ) {
 	if ( object !== undefined ) {
 
 
 		console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
 		console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );

+ 2 - 5
src/helpers/CameraHelper.js

@@ -17,7 +17,8 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 
 
-var _vector, _camera;
+var _vector = new Vector3();
+var _camera = new Camera();
 
 
 function CameraHelper( camera ) {
 function CameraHelper( camera ) {
 
 
@@ -128,8 +129,6 @@ CameraHelper.prototype.constructor = CameraHelper;
 
 
 CameraHelper.prototype.update = function () {
 CameraHelper.prototype.update = function () {
 
 
-	if ( _camera === undefined ) _camera = new Camera();
-
 	var geometry = this.geometry;
 	var geometry = this.geometry;
 	var pointMap = this.pointMap;
 	var pointMap = this.pointMap;
 
 
@@ -183,8 +182,6 @@ CameraHelper.prototype.update = function () {
 
 
 function setPoint( point, pointMap, geometry, camera, x, y, z ) {
 function setPoint( point, pointMap, geometry, camera, x, y, z ) {
 
 
-	if ( _vector === undefined ) _vector = new Vector3();
-
 	_vector.set( x, y, z ).unproject( camera );
 	_vector.set( x, y, z ).unproject( camera );
 
 
 	var points = pointMap[ point ];
 	var points = pointMap[ point ];

+ 3 - 9
src/helpers/DirectionalLightHelper.js

@@ -11,7 +11,9 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 
 
-var _v1, _v2, _v3;
+var _v1 = new Vector3();
+var _v2 = new Vector3();
+var _v3 = new Vector3();
 
 
 function DirectionalLightHelper( light, size, color ) {
 function DirectionalLightHelper( light, size, color ) {
 
 
@@ -65,14 +67,6 @@ DirectionalLightHelper.prototype.dispose = function () {
 
 
 DirectionalLightHelper.prototype.update = function () {
 DirectionalLightHelper.prototype.update = function () {
 
 
-	if ( _v3 === undefined ) {
-
-		_v1 = new Vector3();
-		_v2 = new Vector3();
-		_v3 = new Vector3();
-
-	}
-
 	_v1.setFromMatrixPosition( this.light.matrixWorld );
 	_v1.setFromMatrixPosition( this.light.matrixWorld );
 	_v2.setFromMatrixPosition( this.light.target.matrixWorld );
 	_v2.setFromMatrixPosition( this.light.target.matrixWorld );
 	_v3.subVectors( _v2, _v1 );
 	_v3.subVectors( _v2, _v1 );

+ 3 - 9
src/helpers/FaceNormalsHelper.js

@@ -10,7 +10,9 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
 
-var _v1, _v2, _normalMatrix;
+var _v1 = new Vector3();
+var _v2 = new Vector3();
+var _normalMatrix = new Matrix3();
 
 
 function FaceNormalsHelper( object, size, hex, linewidth ) {
 function FaceNormalsHelper( object, size, hex, linewidth ) {
 
 
@@ -62,14 +64,6 @@ FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
 
 
 FaceNormalsHelper.prototype.update = function () {
 FaceNormalsHelper.prototype.update = function () {
 
 
-	if ( _normalMatrix === undefined ) {
-
-		_v1 = new Vector3();
-		_v2 = new Vector3();
-		_normalMatrix = new Matrix3();
-
-	}
-
 	this.object.updateMatrixWorld( true );
 	this.object.updateMatrixWorld( true );
 
 
 	_normalMatrix.getNormalMatrix( this.object.matrixWorld );
 	_normalMatrix.getNormalMatrix( this.object.matrixWorld );

+ 3 - 9
src/helpers/HemisphereLightHelper.js

@@ -13,7 +13,9 @@ import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
 import { OctahedronBufferGeometry } from '../geometries/OctahedronGeometry.js';
 import { OctahedronBufferGeometry } from '../geometries/OctahedronGeometry.js';
 import { BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferAttribute } from '../core/BufferAttribute.js';
 
 
-var _vector, _color1, _color2;
+var _vector = new Vector3();
+var _color1 = new Color();
+var _color2 = new Color();
 
 
 function HemisphereLightHelper( light, size, color ) {
 function HemisphereLightHelper( light, size, color ) {
 
 
@@ -56,14 +58,6 @@ HemisphereLightHelper.prototype.dispose = function () {
 
 
 HemisphereLightHelper.prototype.update = function () {
 HemisphereLightHelper.prototype.update = function () {
 
 
-	if ( _color2 === undefined ) {
-
-		_vector = new Vector3();
-		_color1 = new Color();
-		_color2 = new Color();
-
-	}
-
 	var mesh = this.children[ 0 ];
 	var mesh = this.children[ 0 ];
 
 
 	if ( this.color !== undefined ) {
 	if ( this.color !== undefined ) {

+ 3 - 9
src/helpers/SkeletonHelper.js

@@ -16,7 +16,9 @@ import { BufferGeometry } from '../core/BufferGeometry.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Object3D } from '../core/Object3D.js';
 import { Object3D } from '../core/Object3D.js';
 
 
-var _vector, _boneMatrix, _matrixWorldInv;
+var _vector = new Vector3();
+var _boneMatrix = new Matrix4();
+var _matrixWorldInv = new Matrix4();
 
 
 function getBoneList( object ) {
 function getBoneList( object ) {
 
 
@@ -85,14 +87,6 @@ SkeletonHelper.prototype.constructor = SkeletonHelper;
 
 
 SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
 SkeletonHelper.prototype.updateMatrixWorld = function ( force ) {
 
 
-	if ( _matrixWorldInv === undefined ) {
-
-		_vector = new Vector3();
-		_boneMatrix = new Matrix4();
-		_matrixWorldInv = new Matrix4();
-
-	}
-
 	var bones = this.bones;
 	var bones = this.bones;
 
 
 	var geometry = this.geometry;
 	var geometry = this.geometry;

+ 1 - 3
src/helpers/SpotLightHelper.js

@@ -11,7 +11,7 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
 
-var _vector;
+var _vector = new Vector3();
 
 
 function SpotLightHelper( light, color ) {
 function SpotLightHelper( light, color ) {
 
 
@@ -70,8 +70,6 @@ SpotLightHelper.prototype.dispose = function () {
 
 
 SpotLightHelper.prototype.update = function () {
 SpotLightHelper.prototype.update = function () {
 
 
-	if ( _vector === undefined ) _vector = new Vector3();
-
 	this.light.updateMatrixWorld();
 	this.light.updateMatrixWorld();
 
 
 	var coneLength = this.light.distance ? this.light.distance : 1000;
 	var coneLength = this.light.distance ? this.light.distance : 1000;

+ 4 - 10
src/helpers/VertexNormalsHelper.js

@@ -10,7 +10,10 @@ import { LineBasicMaterial } from '../materials/LineBasicMaterial.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { Float32BufferAttribute } from '../core/BufferAttribute.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 import { BufferGeometry } from '../core/BufferGeometry.js';
 
 
-var _v1, _v2, _normalMatrix, _keys;
+var _v1 = new Vector3();
+var _v2 = new Vector3();
+var _normalMatrix = new Matrix3();
+var _keys = [ 'a', 'b', 'c' ];
 
 
 function VertexNormalsHelper( object, size, hex, linewidth ) {
 function VertexNormalsHelper( object, size, hex, linewidth ) {
 
 
@@ -61,15 +64,6 @@ VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
 
 
 VertexNormalsHelper.prototype.update = function () {
 VertexNormalsHelper.prototype.update = function () {
 
 
-	if ( _normalMatrix === undefined ) {
-
-		_v1 = new Vector3();
-		_v2 = new Vector3();
-		_normalMatrix = new Matrix3();
-		_keys = [ 'a', 'b', 'c' ];
-
-	}
-
 	this.object.updateMatrixWorld( true );
 	this.object.updateMatrixWorld( true );
 
 
 	_normalMatrix.getNormalMatrix( this.object.matrixWorld );
 	_normalMatrix.getNormalMatrix( this.object.matrixWorld );

+ 12 - 18
src/loaders/Loader.js

@@ -24,7 +24,18 @@ import { Color } from '../math/Color.js';
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
  */
  */
 
 
-var _BlendingMode, _color, _textureLoader, _materialLoader;
+var _BlendingMode = {
+	NoBlending: NoBlending,
+	NormalBlending: NormalBlending,
+	AdditiveBlending: AdditiveBlending,
+	SubtractiveBlending: SubtractiveBlending,
+	MultiplyBlending: MultiplyBlending,
+	CustomBlending: CustomBlending
+};
+
+var _color = new Color();
+var _textureLoader = new TextureLoader();
+var _materialLoader = new MaterialLoader();
 
 
 function Loader() {}
 function Loader() {}
 
 
@@ -87,23 +98,6 @@ Object.assign( Loader.prototype, {
 
 
 	createMaterial: function ( m, texturePath, crossOrigin ) {
 	createMaterial: function ( m, texturePath, crossOrigin ) {
 
 
-		if ( _materialLoader === undefined ) {
-
-			_BlendingMode = {
-				NoBlending: NoBlending,
-				NormalBlending: NormalBlending,
-				AdditiveBlending: AdditiveBlending,
-				SubtractiveBlending: SubtractiveBlending,
-				MultiplyBlending: MultiplyBlending,
-				CustomBlending: CustomBlending
-			};
-
-			_color = new Color();
-			_textureLoader = new TextureLoader();
-			_materialLoader = new MaterialLoader();
-
-		}
-
 		// convert from old material format
 		// convert from old material format
 
 
 		var textures = {};
 		var textures = {};

+ 1 - 5
src/math/Box2.js

@@ -4,7 +4,7 @@ import { Vector2 } from './Vector2.js';
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _vector;
+var _vector = new Vector2();
 
 
 function Box2( min, max ) {
 function Box2( min, max ) {
 
 
@@ -40,8 +40,6 @@ Object.assign( Box2.prototype, {
 
 
 	setFromCenterAndSize: function ( center, size ) {
 	setFromCenterAndSize: function ( center, size ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector2();
-
 		var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
 		var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
 		this.min.copy( center ).sub( halfSize );
 		this.min.copy( center ).sub( halfSize );
 		this.max.copy( center ).add( halfSize );
 		this.max.copy( center ).add( halfSize );
@@ -192,8 +190,6 @@ Object.assign( Box2.prototype, {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector2();
-
 		var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
 		var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
 		return clampedPoint.sub( point ).length();
 		return clampedPoint.sub( point ).length();
 
 

+ 29 - 58
src/math/Box3.js

@@ -1,19 +1,39 @@
 import { Vector3 } from './Vector3.js';
 import { Vector3 } from './Vector3.js';
 
 
+var _points = [
+	new Vector3(),
+	new Vector3(),
+	new Vector3(),
+	new Vector3(),
+	new Vector3(),
+	new Vector3(),
+	new Vector3(),
+	new Vector3()
+];
+var _vector = new Vector3();
+
+// triangle centered vertices
+
+var _v0 = new Vector3();
+var _v1 = new Vector3();
+var _v2 = new Vector3();
+
+// triangle edge vectors
+
+var _f0 = new Vector3();
+var _f1 = new Vector3();
+var _f2 = new Vector3();
+
+var _center = new Vector3();
+var _extents = new Vector3();
+var _triangleNormal = new Vector3();
+var _testAxis = new Vector3();
+
 /**
 /**
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  * @author WestLangley / http://github.com/WestLangley
  * @author WestLangley / http://github.com/WestLangley
  */
  */
 
 
-var _points;
-var _vector;
-
-var _v0, _v1, _v2;
-var _f0, _f1, _f2;
-var _center;
-var _extents;
-var _triangleNormal;
-
 function Box3( min, max ) {
 function Box3( min, max ) {
 
 
 	this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
 	this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
@@ -116,8 +136,6 @@ Object.assign( Box3.prototype, {
 
 
 	setFromCenterAndSize: function ( center, size ) {
 	setFromCenterAndSize: function ( center, size ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
 		var halfSize = _vector.copy( size ).multiplyScalar( 0.5 );
 
 
 		this.min.copy( center ).sub( halfSize );
 		this.min.copy( center ).sub( halfSize );
@@ -222,8 +240,6 @@ Object.assign( Box3.prototype, {
 
 
 	expandByObject: function ( object ) {
 	expandByObject: function ( object ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var i, l;
 		var i, l;
 
 
 		// Computes the world-axis-aligned bounding box of an object (including its children),
 		// Computes the world-axis-aligned bounding box of an object (including its children),
@@ -329,8 +345,6 @@ Object.assign( Box3.prototype, {
 
 
 	intersectsSphere: function ( sphere ) {
 	intersectsSphere: function ( sphere ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		// Find the point on the AABB closest to the sphere center.
 		// Find the point on the AABB closest to the sphere center.
 		this.clampPoint( sphere.center, _vector );
 		this.clampPoint( sphere.center, _vector );
 
 
@@ -388,26 +402,6 @@ Object.assign( Box3.prototype, {
 
 
 	intersectsTriangle: function ( triangle ) {
 	intersectsTriangle: function ( triangle ) {
 
 
-		if ( _v0 === undefined ) {
-
-			// triangle centered vertices
-
-			_v0 = new Vector3();
-			_v1 = new Vector3();
-			_v2 = new Vector3();
-
-			// triangle edge vectors
-
-			_f0 = new Vector3();
-			_f1 = new Vector3();
-			_f2 = new Vector3();
-
-			_center = new Vector3();
-			_extents = new Vector3();
-			_triangleNormal = new Vector3();
-
-		}
-
 		if ( this.isEmpty() ) {
 		if ( this.isEmpty() ) {
 
 
 			return false;
 			return false;
@@ -474,8 +468,6 @@ Object.assign( Box3.prototype, {
 
 
 	distanceToPoint: function ( point ) {
 	distanceToPoint: function ( point ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
 		var clampedPoint = _vector.copy( point ).clamp( this.min, this.max );
 
 
 		return clampedPoint.sub( point ).length();
 		return clampedPoint.sub( point ).length();
@@ -484,8 +476,6 @@ Object.assign( Box3.prototype, {
 
 
 	getBoundingSphere: function ( target ) {
 	getBoundingSphere: function ( target ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 
 			console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
 			console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
@@ -524,21 +514,6 @@ Object.assign( Box3.prototype, {
 
 
 	applyMatrix4: function ( matrix ) {
 	applyMatrix4: function ( matrix ) {
 
 
-		if ( _points === undefined ) {
-
-			_points = [
-				new Vector3(),
-				new Vector3(),
-				new Vector3(),
-				new Vector3(),
-				new Vector3(),
-				new Vector3(),
-				new Vector3(),
-				new Vector3()
-			];
-
-		}
-
 		// transform of empty box is an empty box.
 		// transform of empty box is an empty box.
 		if ( this.isEmpty() ) return this;
 		if ( this.isEmpty() ) return this;
 
 
@@ -575,12 +550,8 @@ Object.assign( Box3.prototype, {
 
 
 } );
 } );
 
 
-var _testAxis;
-
 function satForAxes( axes, v0, v1, v2, extents ) {
 function satForAxes( axes, v0, v1, v2, extents ) {
 
 
-	if ( _testAxis === undefined ) _testAxis = new Vector3();
-
 	var i, j;
 	var i, j;
 
 
 	for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
 	for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {

+ 2 - 5
src/math/Euler.js

@@ -9,7 +9,8 @@ import { _Math } from './Math.js';
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _matrix, _quaternion;
+var _matrix = new Matrix4();
+var _quaternion = new Quaternion();
 
 
 function Euler( x, y, z, order ) {
 function Euler( x, y, z, order ) {
 
 
@@ -257,8 +258,6 @@ Object.assign( Euler.prototype, {
 
 
 	setFromQuaternion: function ( q, order, update ) {
 	setFromQuaternion: function ( q, order, update ) {
 
 
-		if ( _matrix === undefined ) _matrix = new Matrix4();
-
 		_matrix.makeRotationFromQuaternion( q );
 		_matrix.makeRotationFromQuaternion( q );
 
 
 		return this.setFromRotationMatrix( _matrix, order, update );
 		return this.setFromRotationMatrix( _matrix, order, update );
@@ -275,8 +274,6 @@ Object.assign( Euler.prototype, {
 
 
 		// WARNING: this discards revolution information -bhouston
 		// WARNING: this discards revolution information -bhouston
 
 
-		if ( _quaternion === undefined ) _quaternion = new Quaternion();
-
 		_quaternion.setFromEuler( this );
 		_quaternion.setFromEuler( this );
 
 
 		return this.setFromQuaternion( _quaternion, newOrder );
 		return this.setFromQuaternion( _quaternion, newOrder );

+ 2 - 8
src/math/Frustum.js

@@ -8,8 +8,8 @@ import { Plane } from './Plane.js';
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _sphere;
-var _vector;
+var _sphere = new Sphere();
+var _vector = new Vector3();
 
 
 function Frustum( p0, p1, p2, p3, p4, p5 ) {
 function Frustum( p0, p1, p2, p3, p4, p5 ) {
 
 
@@ -85,8 +85,6 @@ Object.assign( Frustum.prototype, {
 
 
 	intersectsObject: function ( object ) {
 	intersectsObject: function ( object ) {
 
 
-		if ( _sphere === undefined ) _sphere = new Sphere();
-
 		var geometry = object.geometry;
 		var geometry = object.geometry;
 
 
 		if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
 		if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
@@ -99,8 +97,6 @@ Object.assign( Frustum.prototype, {
 
 
 	intersectsSprite: function ( sprite ) {
 	intersectsSprite: function ( sprite ) {
 
 
-		if ( _sphere === undefined ) _sphere = new Sphere();
-
 		_sphere.center.set( 0, 0, 0 );
 		_sphere.center.set( 0, 0, 0 );
 		_sphere.radius = 0.7071067811865476;
 		_sphere.radius = 0.7071067811865476;
 		_sphere.applyMatrix4( sprite.matrixWorld );
 		_sphere.applyMatrix4( sprite.matrixWorld );
@@ -133,8 +129,6 @@ Object.assign( Frustum.prototype, {
 
 
 	intersectsBox: function ( box ) {
 	intersectsBox: function ( box ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var planes = this.planes;
 		var planes = this.planes;
 
 
 		for ( var i = 0; i < 6; i ++ ) {
 		for ( var i = 0; i < 6; i ++ ) {

+ 2 - 8
src/math/Line3.js

@@ -5,7 +5,8 @@ import { _Math } from './Math.js';
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _startP, _startEnd;
+var _startP = new Vector3();
+var _startEnd = new Vector3();
 
 
 function Line3( start, end ) {
 function Line3( start, end ) {
 
 
@@ -93,13 +94,6 @@ Object.assign( Line3.prototype, {
 
 
 	closestPointToPointParameter: function ( point, clampToLine ) {
 	closestPointToPointParameter: function ( point, clampToLine ) {
 
 
-		if ( _startP === undefined ) {
-
-			_startP = new Vector3();
-			_startEnd = new Vector3();
-
-		}
-
 		_startP.subVectors( point, this.start );
 		_startP.subVectors( point, this.start );
 		_startEnd.subVectors( this.end, this.start );
 		_startEnd.subVectors( this.end, this.start );
 
 

+ 1 - 3
src/math/Matrix3.js

@@ -7,7 +7,7 @@ import { Vector3 } from './Vector3.js';
  * @author tschw
  * @author tschw
  */
  */
 
 
-var _vector;
+var _vector = new Vector3();
 
 
 function Matrix3() {
 function Matrix3() {
 
 
@@ -94,8 +94,6 @@ Object.assign( Matrix3.prototype, {
 
 
 	applyToBufferAttribute: function ( attribute ) {
 	applyToBufferAttribute: function ( attribute ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		for ( var i = 0, l = attribute.count; i < l; i ++ ) {
 		for ( var i = 0, l = attribute.count; i < l; i ++ ) {
 
 
 			_vector.x = attribute.getX( i );
 			_vector.x = attribute.getX( i );

+ 8 - 30
src/math/Matrix4.js

@@ -1,5 +1,13 @@
 import { Vector3 } from './Vector3.js';
 import { Vector3 } from './Vector3.js';
 
 
+var _v1 = new Vector3();
+var _m1 = new Matrix4();
+var _zero = new Vector3( 0, 0, 0 );
+var _one = new Vector3( 1, 1, 1 );
+var _x = new Vector3();
+var _y = new Vector3();
+var _z = new Vector3();
+
 /**
 /**
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  * @author supereggbert / http://www.paulbrunt.co.uk/
  * @author supereggbert / http://www.paulbrunt.co.uk/
@@ -13,10 +21,6 @@ import { Vector3 } from './Vector3.js';
  * @author WestLangley / http://github.com/WestLangley
  * @author WestLangley / http://github.com/WestLangley
  */
  */
 
 
-var _v1, _m1;
-var _zero, _one;
-var _x, _y, _z;
-
 function Matrix4() {
 function Matrix4() {
 
 
 	this.elements = [
 	this.elements = [
@@ -125,8 +129,6 @@ Object.assign( Matrix4.prototype, {
 
 
 	extractRotation: function ( m ) {
 	extractRotation: function ( m ) {
 
 
-		if ( _v1 === undefined ) _v1 = new Vector3();
-
 		// this method does not support reflection matrices
 		// this method does not support reflection matrices
 
 
 		var te = this.elements;
 		var te = this.elements;
@@ -290,27 +292,12 @@ Object.assign( Matrix4.prototype, {
 
 
 	makeRotationFromQuaternion: function ( q ) {
 	makeRotationFromQuaternion: function ( q ) {
 
 
-		if ( _zero === undefined ) {
-
-			_zero = new Vector3( 0, 0, 0 );
-			_one = new Vector3( 1, 1, 1 );
-
-		}
-
 		return this.compose( _zero, q, _one );
 		return this.compose( _zero, q, _one );
 
 
 	},
 	},
 
 
 	lookAt: function ( eye, target, up ) {
 	lookAt: function ( eye, target, up ) {
 
 
-		if ( _x === undefined ) {
-
-			_x = new Vector3();
-			_y = new Vector3();
-			_z = new Vector3();
-
-		}
-
 		var te = this.elements;
 		var te = this.elements;
 
 
 		_z.subVectors( eye, target );
 		_z.subVectors( eye, target );
@@ -430,8 +417,6 @@ Object.assign( Matrix4.prototype, {
 
 
 	applyToBufferAttribute: function ( attribute ) {
 	applyToBufferAttribute: function ( attribute ) {
 
 
-		if ( _v1 === undefined ) _v1 = new Vector3();
-
 		for ( var i = 0, l = attribute.count; i < l; i ++ ) {
 		for ( var i = 0, l = attribute.count; i < l; i ++ ) {
 
 
 			_v1.x = attribute.getX( i );
 			_v1.x = attribute.getX( i );
@@ -782,13 +767,6 @@ Object.assign( Matrix4.prototype, {
 
 
 	decompose: function ( position, quaternion, scale ) {
 	decompose: function ( position, quaternion, scale ) {
 
 
-		if ( _m1 === undefined ) {
-
-			_m1 = new Matrix4();
-			_v1 = new Vector3();
-
-		}
-
 		var te = this.elements;
 		var te = this.elements;
 
 
 		var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
 		var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();

+ 3 - 17
src/math/Plane.js

@@ -5,7 +5,9 @@ import { Vector3 } from './Vector3.js';
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _vector1, _vector2, _normalMatrix;
+var _vector1 = new Vector3();
+var _vector2 = new Vector3();
+var _normalMatrix = new Matrix3();
 
 
 function Plane( normal, constant ) {
 function Plane( normal, constant ) {
 
 
@@ -49,13 +51,6 @@ Object.assign( Plane.prototype, {
 
 
 	setFromCoplanarPoints: function ( a, b, c ) {
 	setFromCoplanarPoints: function ( a, b, c ) {
 
 
-		if ( _vector1 === undefined ) {
-
-			_vector1 = new Vector3();
-			_vector2 = new Vector3();
-
-		}
-
 		var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
 		var normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
 
 
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
 		// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
@@ -129,8 +124,6 @@ Object.assign( Plane.prototype, {
 
 
 	intersectLine: function ( line, target ) {
 	intersectLine: function ( line, target ) {
 
 
-		if ( _vector1 === undefined ) _vector1 = new Vector3();
-
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 
 			console.warn( 'THREE.Plane: .intersectLine() target is now required' );
 			console.warn( 'THREE.Plane: .intersectLine() target is now required' );
@@ -206,13 +199,6 @@ Object.assign( Plane.prototype, {
 
 
 	applyMatrix4: function ( matrix, optionalNormalMatrix ) {
 	applyMatrix4: function ( matrix, optionalNormalMatrix ) {
 
 
-		if ( _normalMatrix === undefined ) {
-
-			_normalMatrix = new Matrix3();
-			_vector1 = new Vector3();
-
-		}
-
 		var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
 		var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
 
 
 		var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
 		var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );

+ 9 - 29
src/math/Ray.js

@@ -1,13 +1,18 @@
 import { Vector3 } from './Vector3.js';
 import { Vector3 } from './Vector3.js';
 
 
+var _vector = new Vector3();
+var _segCenter = new Vector3();
+var _segDir = new Vector3();
+var _diff = new Vector3();
+
+var _edge1 = new Vector3();
+var _edge2 = new Vector3();
+var _normal = new Vector3();
+
 /**
 /**
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  */
  */
 
 
-var _vector;
-var _segCenter, _segDir, _diff;
-var _diff, _edge1, _edge2, _normal;
-
 function Ray( origin, direction ) {
 function Ray( origin, direction ) {
 
 
 	this.origin = ( origin !== undefined ) ? origin : new Vector3();
 	this.origin = ( origin !== undefined ) ? origin : new Vector3();
@@ -64,8 +69,6 @@ Object.assign( Ray.prototype, {
 
 
 	recast: function ( t ) {
 	recast: function ( t ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		this.origin.copy( this.at( t, _vector ) );
 		this.origin.copy( this.at( t, _vector ) );
 
 
 		return this;
 		return this;
@@ -103,8 +106,6 @@ Object.assign( Ray.prototype, {
 
 
 	distanceSqToPoint: function ( point ) {
 	distanceSqToPoint: function ( point ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		var directionDistance = _vector.subVectors( point, this.origin ).dot( this.direction );
 		var directionDistance = _vector.subVectors( point, this.origin ).dot( this.direction );
 
 
 		// point behind the ray
 		// point behind the ray
@@ -123,14 +124,6 @@ Object.assign( Ray.prototype, {
 
 
 	distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
 	distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
 
 
-		if ( _segCenter === undefined ) {
-
-			_segCenter = new Vector3();
-			_segDir = new Vector3();
-			_diff = new Vector3();
-
-		}
-
 		// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
 		// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
 		// It returns the min distance between the ray and the segment
 		// It returns the min distance between the ray and the segment
 		// defined by v0 and v1
 		// defined by v0 and v1
@@ -250,8 +243,6 @@ Object.assign( Ray.prototype, {
 
 
 	intersectSphere: function ( sphere, target ) {
 	intersectSphere: function ( sphere, target ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		_vector.subVectors( sphere.center, this.origin );
 		_vector.subVectors( sphere.center, this.origin );
 		var tca = _vector.dot( this.direction );
 		var tca = _vector.dot( this.direction );
 		var d2 = _vector.dot( _vector ) - tca * tca;
 		var d2 = _vector.dot( _vector ) - tca * tca;
@@ -424,8 +415,6 @@ Object.assign( Ray.prototype, {
 
 
 	intersectsBox: function ( box ) {
 	intersectsBox: function ( box ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		return this.intersectBox( box, _vector ) !== null;
 		return this.intersectBox( box, _vector ) !== null;
 
 
 	},
 	},
@@ -434,15 +423,6 @@ Object.assign( Ray.prototype, {
 
 
 		// Compute the offset origin, edges, and normal.
 		// Compute the offset origin, edges, and normal.
 
 
-		if ( _diff === undefined ) {
-
-			_diff = new Vector3();
-			_edge1 = new Vector3();
-			_edge2 = new Vector3();
-			_normal = new Vector3();
-
-		}
-
 		// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
 		// from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
 
 
 		_edge1.subVectors( b, a );
 		_edge1.subVectors( b, a );

+ 2 - 4
src/math/Sphere.js

@@ -1,13 +1,13 @@
 import { Box3 } from './Box3.js';
 import { Box3 } from './Box3.js';
 import { Vector3 } from './Vector3.js';
 import { Vector3 } from './Vector3.js';
 
 
+var _box = new Box3();
+
 /**
 /**
  * @author bhouston / http://clara.io
  * @author bhouston / http://clara.io
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-var _box;
-
 function Sphere( center, radius ) {
 function Sphere( center, radius ) {
 
 
 	this.center = ( center !== undefined ) ? center : new Vector3();
 	this.center = ( center !== undefined ) ? center : new Vector3();
@@ -28,8 +28,6 @@ Object.assign( Sphere.prototype, {
 
 
 	setFromPoints: function ( points, optionalCenter ) {
 	setFromPoints: function ( points, optionalCenter ) {
 
 
-		if ( _box === undefined ) _box = new Box3();
-
 		var center = this.center;
 		var center = this.center;
 
 
 		if ( optionalCenter !== undefined ) {
 		if ( optionalCenter !== undefined ) {

+ 11 - 41
src/math/Triangle.js

@@ -5,8 +5,17 @@ import { Vector3 } from './Vector3.js';
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-var _v0, _v1, _v2, _v3;
-var _vab, _vac, _vbc, _vap, _vbp, _vcp;
+var _v0 = new Vector3();
+var _v1 = new Vector3();
+var _v2 = new Vector3();
+var _v3 = new Vector3();
+
+var _vab = new Vector3();
+var _vac = new Vector3();
+var _vbc = new Vector3();
+var _vap = new Vector3();
+var _vbp = new Vector3();
+var _vcp = new Vector3();
 
 
 function Triangle( a, b, c ) {
 function Triangle( a, b, c ) {
 
 
@@ -20,8 +29,6 @@ Object.assign( Triangle, {
 
 
 	getNormal: function ( a, b, c, target ) {
 	getNormal: function ( a, b, c, target ) {
 
 
-		if ( _v0 === undefined ) _v0 = new Vector3();
-
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 
 			console.warn( 'THREE.Triangle: .getNormal() target is now required' );
 			console.warn( 'THREE.Triangle: .getNormal() target is now required' );
@@ -48,14 +55,6 @@ Object.assign( Triangle, {
 	// based on: http://www.blackpawn.com/texts/pointinpoly/default.html
 	// based on: http://www.blackpawn.com/texts/pointinpoly/default.html
 	getBarycoord: function ( point, a, b, c, target ) {
 	getBarycoord: function ( point, a, b, c, target ) {
 
 
-		if ( _v2 === undefined ) {
-
-			_v0 = new Vector3();
-			_v1 = new Vector3();
-			_v2 = new Vector3();
-
-		}
-
 		_v0.subVectors( c, a );
 		_v0.subVectors( c, a );
 		_v1.subVectors( b, a );
 		_v1.subVectors( b, a );
 		_v2.subVectors( point, a );
 		_v2.subVectors( point, a );
@@ -95,8 +94,6 @@ Object.assign( Triangle, {
 
 
 	containsPoint: function ( point, a, b, c ) {
 	containsPoint: function ( point, a, b, c ) {
 
 
-		if ( _v3 === undefined ) _v3 = new Vector3();
-
 		Triangle.getBarycoord( point, a, b, c, _v3 );
 		Triangle.getBarycoord( point, a, b, c, _v3 );
 
 
 		return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
 		return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
@@ -105,8 +102,6 @@ Object.assign( Triangle, {
 
 
 	getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
 	getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) {
 
 
-		if ( _v3 === undefined ) _v3 = new Vector3();
-
 		this.getBarycoord( point, p1, p2, p3, _v3 );
 		this.getBarycoord( point, p1, p2, p3, _v3 );
 
 
 		target.set( 0, 0 );
 		target.set( 0, 0 );
@@ -120,13 +115,6 @@ Object.assign( Triangle, {
 
 
 	isFrontFacing: function ( a, b, c, direction ) {
 	isFrontFacing: function ( a, b, c, direction ) {
 
 
-		if ( _v1 === undefined ) {
-
-			_v0 = new Vector3();
-			_v1 = new Vector3();
-
-		}
-
 		_v0.subVectors( c, b );
 		_v0.subVectors( c, b );
 		_v1.subVectors( a, b );
 		_v1.subVectors( a, b );
 
 
@@ -177,13 +165,6 @@ Object.assign( Triangle.prototype, {
 
 
 	getArea: function () {
 	getArea: function () {
 
 
-		if ( _v1 === undefined ) {
-
-			_v0 = new Vector3();
-			_v1 = new Vector3();
-
-		}
-
 		_v0.subVectors( this.c, this.b );
 		_v0.subVectors( this.c, this.b );
 		_v1.subVectors( this.a, this.b );
 		_v1.subVectors( this.a, this.b );
 
 
@@ -255,17 +236,6 @@ Object.assign( Triangle.prototype, {
 
 
 	closestPointToPoint: function ( p, target ) {
 	closestPointToPoint: function ( p, target ) {
 
 
-		if ( _vab === undefined ) {
-
-			_vab = new Vector3();
-			_vac = new Vector3();
-			_vbc = new Vector3();
-			_vap = new Vector3();
-			_vbp = new Vector3();
-			_vcp = new Vector3();
-
-		}
-
 		if ( target === undefined ) {
 		if ( target === undefined ) {
 
 
 			console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
 			console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );

+ 2 - 9
src/math/Vector3.js

@@ -10,7 +10,8 @@ import { Quaternion } from './Quaternion.js';
  * @author WestLangley / http://github.com/WestLangley
  * @author WestLangley / http://github.com/WestLangley
  */
  */
 
 
-var _vector, _quaternion;
+var _vector = new Vector3();
+var _quaternion = new Quaternion();
 
 
 function Vector3( x, y, z ) {
 function Vector3( x, y, z ) {
 
 
@@ -235,8 +236,6 @@ Object.assign( Vector3.prototype, {
 
 
 	applyEuler: function ( euler ) {
 	applyEuler: function ( euler ) {
 
 
-		if ( _quaternion === undefined ) _quaternion = new Quaternion();
-
 		if ( ! ( euler && euler.isEuler ) ) {
 		if ( ! ( euler && euler.isEuler ) ) {
 
 
 			console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
 			console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
@@ -249,8 +248,6 @@ Object.assign( Vector3.prototype, {
 
 
 	applyAxisAngle: function ( axis, angle ) {
 	applyAxisAngle: function ( axis, angle ) {
 
 
-		if ( _quaternion === undefined ) _quaternion = new Quaternion();
-
 		return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
 		return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
 
 
 	},
 	},
@@ -539,8 +536,6 @@ Object.assign( Vector3.prototype, {
 
 
 	projectOnPlane: function ( planeNormal ) {
 	projectOnPlane: function ( planeNormal ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		_vector.copy( this ).projectOnVector( planeNormal );
 		_vector.copy( this ).projectOnVector( planeNormal );
 
 
 		return this.sub( _vector );
 		return this.sub( _vector );
@@ -549,8 +544,6 @@ Object.assign( Vector3.prototype, {
 
 
 	reflect: function ( normal ) {
 	reflect: function ( normal ) {
 
 
-		if ( _vector === undefined ) _vector = new Vector3();
-
 		// reflect incident vector off plane orthogonal to normal
 		// reflect incident vector off plane orthogonal to normal
 		// normal is assumed to have unit length
 		// normal is assumed to have unit length
 
 

+ 2 - 10
src/objects/LOD.js

@@ -7,7 +7,8 @@ import { Object3D } from '../core/Object3D.js';
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-var _v1, _v2;
+var _v1 = new Vector3();
+var _v2 = new Vector3();
 
 
 function LOD() {
 function LOD() {
 
 
@@ -96,8 +97,6 @@ LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( raycaster, intersects ) {
 
 
-		if ( _v1 === undefined ) _v1 = new Vector3();
-
 		_v1.setFromMatrixPosition( this.matrixWorld );
 		_v1.setFromMatrixPosition( this.matrixWorld );
 
 
 		var distance = raycaster.ray.origin.distanceTo( _v1 );
 		var distance = raycaster.ray.origin.distanceTo( _v1 );
@@ -108,13 +107,6 @@ LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	update: function ( camera ) {
 	update: function ( camera ) {
 
 
-		if ( _v2 === undefined ) {
-
-			_v1 = new Vector3();
-			_v2 = new Vector3();
-
-		}
-
 		var levels = this.levels;
 		var levels = this.levels;
 
 
 		if ( levels.length > 1 ) {
 		if ( levels.length > 1 ) {

+ 5 - 17
src/objects/Line.js

@@ -11,8 +11,11 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-var _start, _end;
-var _inverseMatrix, _ray, _sphere;
+var _start = new Vector3();
+var _end = new Vector3();
+var _inverseMatrix = new Matrix4();
+var _ray = new Ray();
+var _sphere = new Sphere();
 
 
 function Line( geometry, material, mode ) {
 function Line( geometry, material, mode ) {
 
 
@@ -39,13 +42,6 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	computeLineDistances: function () {
 	computeLineDistances: function () {
 
 
-		if ( _end === undefined ) {
-
-			_start = new Vector3();
-			_end = new Vector3();
-
-		}
-
 		var geometry = this.geometry;
 		var geometry = this.geometry;
 
 
 		if ( geometry.isBufferGeometry ) {
 		if ( geometry.isBufferGeometry ) {
@@ -97,14 +93,6 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( raycaster, intersects ) {
 
 
-		if ( _sphere === undefined ) {
-
-			_inverseMatrix = new Matrix4();
-			_ray = new Ray();
-			_sphere = new Sphere();
-
-		}
-
 		var precision = raycaster.linePrecision;
 		var precision = raycaster.linePrecision;
 
 
 		var geometry = this.geometry;
 		var geometry = this.geometry;

+ 2 - 8
src/objects/LineSegments.js

@@ -6,7 +6,8 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
  * @author mrdoob / http://mrdoob.com/
  * @author mrdoob / http://mrdoob.com/
  */
  */
 
 
-var _start, _end;
+var _start = new Vector3();
+var _end = new Vector3();
 
 
 function LineSegments( geometry, material ) {
 function LineSegments( geometry, material ) {
 
 
@@ -24,13 +25,6 @@ LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
 
 
 	computeLineDistances: function () {
 	computeLineDistances: function () {
 
 
-		if ( _end === undefined ) {
-
-			_start = new Vector3();
-			_end = new Vector3();
-
-		}
-
 		var geometry = this.geometry;
 		var geometry = this.geometry;
 
 
 		if ( geometry.isBufferGeometry ) {
 		if ( geometry.isBufferGeometry ) {

+ 22 - 33
src/objects/Mesh.js

@@ -17,12 +17,28 @@ import { BufferGeometry } from '../core/BufferGeometry.js';
  * @author jonobr1 / http://jonobr1.com/
  * @author jonobr1 / http://jonobr1.com/
  */
  */
 
 
-var _inverseMatrix, _ray, _sphere;
-var _vA, _vB, _vC;
-var _tempA, _tempB, _tempC;
-var _morphA, _morphB, _morphC;
-var _uvA, _uvB, _uvC;
-var _intersectionPoint, _intersectionPointWorld;
+var _inverseMatrix = new Matrix4();
+var _ray = new Ray();
+var _sphere = new Sphere();
+
+var _vA = new Vector3();
+var _vB = new Vector3();
+var _vC = new Vector3();
+
+var _tempA = new Vector3();
+var _tempB = new Vector3();
+var _tempC = new Vector3();
+
+var _morphA = new Vector3();
+var _morphB = new Vector3();
+var _morphC = new Vector3();
+
+var _uvA = new Vector2();
+var _uvB = new Vector2();
+var _uvC = new Vector2();
+
+var _intersectionPoint = new Vector3();
+var _intersectionPointWorld = new Vector3();
 
 
 function Mesh( geometry, material ) {
 function Mesh( geometry, material ) {
 
 
@@ -121,33 +137,6 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( raycaster, intersects ) {
 
 
-		if ( _intersectionPointWorld === undefined ) {
-
-			_inverseMatrix = new Matrix4();
-			_ray = new Ray();
-			_sphere = new Sphere();
-
-			_vA = new Vector3();
-			_vB = new Vector3();
-			_vC = new Vector3();
-
-			_tempA = new Vector3();
-			_tempB = new Vector3();
-			_tempC = new Vector3();
-
-			_morphA = new Vector3();
-			_morphB = new Vector3();
-			_morphC = new Vector3();
-
-			_uvA = new Vector2();
-			_uvB = new Vector2();
-			_uvC = new Vector2();
-
-			_intersectionPoint = new Vector3();
-			_intersectionPointWorld = new Vector3();
-
-		}
-
 		var geometry = this.geometry;
 		var geometry = this.geometry;
 		var material = this.material;
 		var material = this.material;
 		var matrixWorld = this.matrixWorld;
 		var matrixWorld = this.matrixWorld;

+ 4 - 10
src/objects/Points.js

@@ -10,7 +10,10 @@ import { BufferGeometry } from '../core/BufferGeometry.js';
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
  */
  */
 
 
-var _inverseMatrix, _ray, _sphere, _position;
+var _inverseMatrix = new Matrix4();
+var _ray = new Ray();
+var _sphere = new Sphere();
+var _position = new Vector3();
 
 
 function Points( geometry, material ) {
 function Points( geometry, material ) {
 
 
@@ -33,15 +36,6 @@ Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( raycaster, intersects ) {
 
 
-		if ( _sphere === undefined ) {
-
-			_inverseMatrix = new Matrix4();
-			_ray = new Ray();
-			_sphere = new Sphere();
-			_position = new Vector3();
-
-		}
-
 		var geometry = this.geometry;
 		var geometry = this.geometry;
 		var matrixWorld = this.matrixWorld;
 		var matrixWorld = this.matrixWorld;
 		var threshold = raycaster.params.Points.threshold;
 		var threshold = raycaster.params.Points.threshold;

+ 2 - 8
src/objects/Skeleton.js

@@ -7,7 +7,8 @@ import { Matrix4 } from '../math/Matrix4.js';
  * @author ikerr / http://verold.com
  * @author ikerr / http://verold.com
  */
  */
 
 
-var _offsetMatrix, _identityMatrix;
+var _offsetMatrix = new Matrix4();
+var _identityMatrix = new Matrix4();
 
 
 function Skeleton( bones, boneInverses ) {
 function Skeleton( bones, boneInverses ) {
 
 
@@ -117,13 +118,6 @@ Object.assign( Skeleton.prototype, {
 
 
 	update: function () {
 	update: function () {
 
 
-		if ( _identityMatrix === undefined ) {
-
-			_offsetMatrix = new Matrix4();
-			_identityMatrix = new Matrix4();
-
-		}
-
 		var bones = this.bones;
 		var bones = this.bones;
 		var boneInverses = this.boneInverses;
 		var boneInverses = this.boneInverses;
 		var boneMatrices = this.boneMatrices;
 		var boneMatrices = this.boneMatrices;

+ 15 - 24
src/objects/Sprite.js

@@ -15,10 +15,21 @@ import { SpriteMaterial } from '../materials/SpriteMaterial.js';
 
 
 var _geometry;
 var _geometry;
 
 
-var _intersectPoint, _worldScale, _mvPosition;
-var _alignedPosition, _rotatedPosition, _viewWorldMatrix;
-var _vA, _vB, _vC;
-var _uvA, _uvB, _uvC;
+var _intersectPoint = new Vector3();
+var _worldScale = new Vector3();
+var _mvPosition = new Vector3();
+
+var _alignedPosition = new Vector2();
+var _rotatedPosition = new Vector2();
+var _viewWorldMatrix = new Matrix4();
+
+var _vA = new Vector3();
+var _vB = new Vector3();
+var _vC = new Vector3();
+
+var _uvA = new Vector2();
+var _uvB = new Vector2();
+var _uvC = new Vector2();
 
 
 function Sprite( material ) {
 function Sprite( material ) {
 
 
@@ -60,26 +71,6 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	raycast: function ( raycaster, intersects ) {
 	raycast: function ( raycaster, intersects ) {
 
 
-		if ( _uvC === undefined ) {
-
-			_intersectPoint = new Vector3();
-			_worldScale = new Vector3();
-			_mvPosition = new Vector3();
-
-			_alignedPosition = new Vector2();
-			_rotatedPosition = new Vector2();
-			_viewWorldMatrix = new Matrix4();
-
-			_vA = new Vector3();
-			_vB = new Vector3();
-			_vC = new Vector3();
-
-			_uvA = new Vector2();
-			_uvB = new Vector2();
-			_uvC = new Vector2();
-
-		}
-
 		_worldScale.setFromMatrixScale( this.matrixWorld );
 		_worldScale.setFromMatrixScale( this.matrixWorld );
 
 
 		_viewWorldMatrix.copy( raycaster._camera.matrixWorld );
 		_viewWorldMatrix.copy( raycaster._camera.matrixWorld );