浏览代码

support arrows with zero-length tails

tinaun 10 年之前
父节点
当前提交
9e2103f9ce
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      src/extras/helpers/ArrowHelper.js

+ 11 - 7
src/extras/helpers/ArrowHelper.js

@@ -34,10 +34,12 @@ THREE.ArrowHelper = ( function () {
 		if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 		if ( headWidth === undefined ) headWidth = 0.2 * headLength;
 
 
 		this.position.copy( origin );
 		this.position.copy( origin );
-
-		this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
-		this.line.matrixAutoUpdate = false;
-		this.add( this.line );
+		
+		if ( headLength < length ) {
+			this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
+			this.line.matrixAutoUpdate = false;
+			this.add( this.line );
+		}
 
 
 		this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
 		this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
 		this.cone.matrixAutoUpdate = false;
 		this.cone.matrixAutoUpdate = false;
@@ -89,8 +91,10 @@ THREE.ArrowHelper.prototype.setLength = function ( length, 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;
 
 
-	this.line.scale.set( 1, length - headLength, 1 );
-	this.line.updateMatrix();
+	if ( headLength < length ){
+		this.line.scale.set( 1, length - headLength, 1 );
+		this.line.updateMatrix();
+	}
 
 
 	this.cone.scale.set( headWidth, headLength, headWidth );
 	this.cone.scale.set( headWidth, headLength, headWidth );
 	this.cone.position.y = length;
 	this.cone.position.y = length;
@@ -100,7 +104,7 @@ THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth
 
 
 THREE.ArrowHelper.prototype.setColor = function ( color ) {
 THREE.ArrowHelper.prototype.setColor = function ( color ) {
 
 
-	this.line.material.color.set( color );
+	if ( this.line !== undefined ) this.line.material.color.set( color );
 	this.cone.material.color.set( color );
 	this.cone.material.color.set( color );
 
 
 };
 };