From 2d49fd2b8492e63d881c26b1761cb74db1d0ade9 Mon Sep 17 00:00:00 2001 From: sroucheray Date: Sun, 17 Apr 2011 22:35:18 +0200 Subject: [PATCH 1/2] Trident is a utility 3D object, it simply displays the 3 axis arrows. It can be added to the scene or as a child of any Object3D. It is specially useful for debugging purpose. The Trident name is borrowed from the Away3D project http://away3d.com/livedocs/3.6.0_lib/away3d/primitives/Trident.html --- src/extras/objects/Trident.js | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/extras/objects/Trident.js diff --git a/src/extras/objects/Trident.js b/src/extras/objects/Trident.js new file mode 100644 index 00000000..167a39aa --- /dev/null +++ b/src/extras/objects/Trident.js @@ -0,0 +1,77 @@ +/** + * @author sroucheray / http://sroucheray.org/ + */ + +/** + * @constructor + * Three axis representing the cartesian coordinates + * @param xAxisColor {number} + * @param yAxisColor {number} + * @param zAxisColor {number} + * @param showArrows {Boolean} + * @param length {number} + * @param scale {number} + * + * @see THREE.Trident.defaultParams + */ +THREE.Trident = function ( params /** Object */) { + + THREE.Object3D.call( this ); + + var hPi = Math.PI / 2, cone; + + params = params || THREE.Trident.defaultParams; + + if(params !== THREE.Trident.defaultParams){ + for ( var key in THREE.Trident.defaultParams) { + if(!params.hasOwnProperty(key)){ + params[key] = THREE.Trident.defaultParams[key]; + } + } + } + + this.scale = new THREE.Vector3( params.scale, params.scale, params.scale ); + this.addChild( getSegment( new THREE.Vector3(params.length,0,0), params.xAxisColor ) ); + this.addChild( getSegment( new THREE.Vector3(0,params.length,0), params.yAxisColor ) ); + this.addChild( getSegment( new THREE.Vector3(0,0,params.length), params.zAxisColor ) ); + + if(params.showArrows){ + cone = getCone(params.xAxisColor); + cone.rotation.y = - hPi; + cone.position.x = params.length; + this.addChild( cone ); + + cone = getCone(params.yAxisColor); + cone.rotation.x = hPi; + cone.position.y = params.length; + this.addChild( cone ); + + cone = getCone(params.zAxisColor); + cone.rotation.y = Math.PI; + cone.position.z = params.length; + this.addChild( cone ); + } + + function getCone ( color ) { + //0.1 required to get a cone with a mapped bottom face + return new THREE.Mesh( new THREE.Cylinder( 30, 0.1, params.length / 20, params.length / 5 ), new THREE.MeshBasicMaterial( { color : color } ) ); + } + + function getSegment ( point, color ){ + var geom = new THREE.Geometry(); + geom.vertices = [new THREE.Vertex(), new THREE.Vertex(point)]; + return new THREE.Line( geom, new THREE.MeshBasicMaterial( { color : color } ) ); + } +}; + +THREE.Trident.prototype = new THREE.Object3D(); +THREE.Trident.prototype.constructor = THREE.Trident; + +THREE.Trident.defaultParams = { + xAxisColor : 0xFF0000, + yAxisColor : 0x00FF00, + zAxisColor : 0x0000FF, + showArrows : true, + length : 100, + scale : 1 +}; \ No newline at end of file From 39e993d50d77a54b692b9b72a8bdebbe42b61522 Mon Sep 17 00:00:00 2001 From: sroucheray Date: Sun, 17 Apr 2011 22:41:32 +0200 Subject: [PATCH 2/2] Include Trident.js in the EXTRAS_FILES Build array --- utils/build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/build.py b/utils/build.py index bc4efadc..61f34388 100644 --- a/utils/build.py +++ b/utils/build.py @@ -105,6 +105,7 @@ EXTRAS_FILES = [ 'extras/io/BinaryLoader.js', 'extras/io/SceneLoader.js', 'extras/objects/MarchingCubes.js', +'extras/objects/Trident.js', 'extras/physics/Collisions.js', 'extras/physics/CollisionUtils.js' ]