瀏覽代碼

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

sroucheray 14 年之前
父節點
當前提交
2d49fd2b84
共有 1 個文件被更改,包括 77 次插入0 次删除
  1. 77 0
      src/extras/objects/Trident.js

+ 77 - 0
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
+};