소스 검색

ArrowHelper: fix undefined reference when using zero-length tails

Commit 9e2103f9ce added support for zero-length tails by conditionally
creating the line object. However it kept using that object
unconditionally in some places (such as setLength), which results in
undefined references if an ArrowHelper is initially created with a
zero-size tail and then made longer by calling setLength().

This patch fixes this problem by always creating the tail object and
limiting its minimum length to 0. This also simplifies the code a bit.
Alexandre Courbot 10 년 전
부모
커밋
b53649ab72
1개의 변경된 파일6개의 추가작업 그리고 10개의 파일을 삭제
  1. 6 10
      src/extras/helpers/ArrowHelper.js

+ 6 - 10
src/extras/helpers/ArrowHelper.js

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