提交 0f5bc025 编写于 作者: M Mr.doob

ArrowHelper: Reuse line geometry and cone geometry.

上级 55b66f6e
......@@ -14,38 +14,42 @@
* headWidth - Number
*/
THREE.ArrowHelper = function ( dir, origin, length, color, headLength, headWidth ) {
// dir is assumed to be normalized
THREE.Object3D.call( this );
if ( color === undefined ) color = 0xffff00;
if ( length === undefined ) length = 1;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.position.copy( origin );
THREE.ArrowHelper = ( function (){
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ) );
lineGeometry.vertices.push( new THREE.Vector3( 0, 1, 0 ) );
this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
this.line.matrixAutoUpdate = false;
this.add( this.line );
var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
this.cone.matrixAutoUpdate = false;
this.add( this.cone );
return function ( dir, origin, length, color, headLength, headWidth ) {
// dir is assumed to be normalized
this.setDirection( dir );
this.setLength( length, headLength, headWidth );
THREE.Object3D.call( this );
};
if ( color === undefined ) color = 0xffff00;
if ( length === undefined ) length = 1;
if ( headLength === undefined ) headLength = 0.2 * length;
if ( headWidth === undefined ) headWidth = 0.2 * headLength;
this.position.copy( origin );
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;
this.add( this.cone );
this.setDirection( dir );
this.setLength( length, headLength, headWidth );
}
}() );
THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册