diff --git a/src/extras/helpers/ArrowHelper.js b/src/extras/helpers/ArrowHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..66602dad3813896712f291738bb5c106890ab2de --- /dev/null +++ b/src/extras/helpers/ArrowHelper.js @@ -0,0 +1,44 @@ +/** + * @author WestLangley / https://github.com/WestLangley + * @author zz85 / https://github.com/zz85 + */ +THREE.ArrowHelper = function (origin, dir, scale, color) { + + THREE.Object3D.call( this ); + + // line + var lineGeometry = new THREE.Geometry(); + lineGeometry.vertices.push( new THREE.Vertex() ); + lineGeometry.vertices.push( new THREE.Vertex( new THREE.Vector3( 0, 1, 0 ) ) ); + line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color : color } ) ); + this.add( line ); + + // tip + var coneGeometry = new THREE.CylinderGeometry( 0, 0.05, 0.25, 5, 1 ); + cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color : color } ) ); + cone.position.set( 0, 1, 0 ); + this.add( cone ); + + // position + this.position = origin; + + this.orientate(dir); + + this.scale.set( scale, scale, scale ); + +}; + +THREE.ArrowHelper.prototype = new THREE.Object3D(); +THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper; + +THREE.ArrowHelper.prototype.orientate = function(dir) { + // orientation - object matrix + var axis = new THREE.Vector3( 0, 1, 0 ).crossSelf( dir ); + var radians = Math.acos( new THREE.Vector3( 0, 1, 0 ).dot( dir.normalize() ) ); + var rotationMatrix = new THREE.Matrix4(); + rotationMatrix.setRotationAxis( axis.normalize(), radians ); + this.matrix.multiplySelf( rotationMatrix ); + + // orientation - euler rotation vector + this.rotation.getRotationFromMatrix( this.matrix, this.scale ); +}; \ No newline at end of file diff --git a/utils/build.py b/utils/build.py index 8464cbdd756259706047319ea5097d7bb53945ec..c7decb60b223b5db7e4fd5ad5d26b440b3e05295 100644 --- a/utils/build.py +++ b/utils/build.py @@ -121,6 +121,7 @@ EXTRAS_FILES = [ 'extras/geometries/OctahedronGeometry.js', 'extras/geometries/TetrahedronGeometry.js', 'extras/helpers/AxisHelper.js', +'extras/helpers/ArrowHelper.js', 'extras/helpers/CameraHelper.js', 'extras/modifiers/SubdivisionModifier.js', 'extras/loaders/Loader.js',