1 /**
  2  * @author clockworkgeek / https://github.com/clockworkgeek
  3  * @author timothypratley / https://github.com/timothypratley
  4  */
  5 
  6 /**@constructor*/
  7 THREE.PolyhedronGeometry = function ( vertices, faces, radius, detail ) {
  8 
  9 	THREE.Geometry.call( this );
 10 
 11 	radius = radius || 1;
 12 	detail = detail || 0;
 13 
 14 	var that = this;
 15 
 16 	for ( var i = 0, l = vertices.length; i < l; i ++ ) {
 17 
 18 		prepare( new THREE.Vector3( vertices[ i ][ 0 ], vertices[ i ][ 1 ], vertices[ i ][ 2 ] ) );
 19 
 20 	}
 21 
 22 	var midpoints = [], p = this.vertices;
 23 
 24 	for ( var i = 0, l = faces.length; i < l; i ++ ) {
 25 
 26 		make( p[ faces[ i ][ 0 ] ], p[ faces[ i ][ 1 ] ], p[ faces[ i ][ 2 ] ], detail );
 27 
 28 	}
 29 
 30 	this.mergeVertices();
 31 
 32 	// Apply radius
 33 
 34 	for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
 35 
 36 		this.vertices[ i ].multiplyScalar( radius );
 37 
 38 	}
 39 
 40 
 41 	// Project vector onto sphere's surface
 42 
 43 	function prepare( vector ) {
 44 
 45 		var vertex = vector.normalize().clone();
 46 		vertex.index = that.vertices.push( vertex ) - 1;
 47 
 48 		// Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
 49 
 50 		var u = azimuth( vector ) / 2 / Math.PI + 0.5;
 51 		var v = inclination( vector ) / Math.PI + 0.5;
 52 		vertex.uv = new THREE.UV( u, 1 - v );
 53 
 54 		return vertex;
 55 
 56 	}
 57 
 58 
 59 	// Approximate a curved face with recursively sub-divided triangles.
 60 
 61 	function make( v1, v2, v3, detail ) {
 62 
 63 		if ( detail < 1 ) {
 64 
 65 			var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
 66 			face.centroid.addSelf( v1 ).addSelf( v2 ).addSelf( v3 ).divideScalar( 3 );
 67 			face.normal = face.centroid.clone().normalize();
 68 			that.faces.push( face );
 69 
 70 			var azi = azimuth( face.centroid );
 71 			that.faceVertexUvs[ 0 ].push( [
 72 				correctUV( v1.uv, v1, azi ),
 73 				correctUV( v2.uv, v2, azi ),
 74 				correctUV( v3.uv, v3, azi )
 75 			] );
 76 
 77 		} else {
 78 
 79 			detail -= 1;
 80 
 81 			// split triangle into 4 smaller triangles
 82 
 83 			make( v1, midpoint( v1, v2 ), midpoint( v1, v3 ), detail ); // top quadrant
 84 			make( midpoint( v1, v2 ), v2, midpoint( v2, v3 ), detail ); // left quadrant
 85 			make( midpoint( v1, v3 ), midpoint( v2, v3 ), v3, detail ); // right quadrant
 86 			make( midpoint( v1, v2 ), midpoint( v2, v3 ), midpoint( v1, v3 ), detail ); // center quadrant
 87 
 88 		}
 89 
 90 	}
 91 
 92 	function midpoint( v1, v2 ) {
 93 
 94 		if ( !midpoints[ v1.index ] ) midpoints[ v1.index ] = [];
 95 		if ( !midpoints[ v2.index ] ) midpoints[ v2.index ] = [];
 96 
 97 		var mid = midpoints[ v1.index ][ v2.index ];
 98 
 99 		if ( mid === undefined ) {
100 
101 			// generate mean point and project to surface with prepare()
102 
103 			midpoints[ v1.index ][ v2.index ] = midpoints[ v2.index ][ v1.index ] = mid = prepare(
104 				new THREE.Vector3().add( v1, v2 ).divideScalar( 2 )
105 			);
106 		}
107 
108 		return mid;
109 
110 	}
111 
112 
113 	// Angle around the Y axis, counter-clockwise when looking from above.
114 
115 	function azimuth( vector ) {
116 
117 		return Math.atan2( vector.z, -vector.x );
118 
119 	}
120 
121 
122 	// Angle above the XZ plane.
123 
124 	function inclination( vector ) {
125 
126 		return Math.atan2( -vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
127 
128 	}
129 
130 
131 	// Texture fixing helper. Spheres have some odd behaviours.
132 
133 	function correctUV( uv, vector, azimuth ) {
134 
135 		if ( ( azimuth < 0 ) && ( uv.u === 1 ) ) uv = new THREE.UV( uv.u - 1, uv.v );
136 		if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.UV( azimuth / 2 / Math.PI + 0.5, uv.v );
137 		return uv;
138 
139 	}
140 
141 	this.computeCentroids();
142 
143 	this.boundingSphere = { radius: radius };
144 
145 };
146 
147 THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
148 

nike free rn new balance hombre baratas cinturones gucci ugg rebajas cinturon gucci ray ban baratas nike cortez peuterey mujer christian louboutin madrid mbt zapatos gafas ray ban baratas mbt ofertas air max blancas mbt barcelona nike air max 90 woolrich barcelona nike mujer botas ugg gafas de sol carrera aratas air max 2016 baratas oakley baratas nike air max 2016

mbt skor nike sverige louboutin skor hollister sverige polo ralph lauren skjorta woolrich jacka dam canada goose jacka woolrich jacka ray ban rea canada goose rea michael kors rea new balance skor ralph lauren skjorta new balance rea uggs sverige lacoste rea christian louboutin skor moncler jacka nike shox barbour jacka uggs rea