Browse Source

ArrowHelper: Clean up.

Mugen87 6 years ago
parent
commit
1cb8aced30
1 changed files with 11 additions and 6 deletions
  1. 11 6
      src/helpers/ArrowHelper.js

+ 11 - 6
src/helpers/ArrowHelper.js

@@ -25,12 +25,7 @@ import { Line } from '../objects/Line.js';
 import { Vector3 } from '../math/Vector3.js';
 
 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 );
+var _lineGeometry, _coneGeometry;
 
 function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 
@@ -45,6 +40,16 @@ function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
 	if ( headLength === undefined ) headLength = 0.2 * length;
 	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.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color } ) );