1 /**
  2  * @author zz85 / http://www.lab4games.net/zz85/blog
  3  * Creates free form 2d path using series of points, lines or curves.
  4  *
  5  **/
  6 
  7 /**@constructor*/
  8 THREE.Path = function ( points ) {
  9 
 10 	THREE.CurvePath.call(this);
 11 
 12 	this.actions = [];
 13 
 14 	if ( points ) {
 15 
 16 		this.fromPoints( points );
 17 
 18 	}
 19 
 20 };
 21 
 22 THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
 23 
 24 /**@namespace*/
 25 THREE.PathActions = {
 26 
 27 	MOVE_TO: 'moveTo',
 28 	LINE_TO: 'lineTo',
 29 	QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
 30 	BEZIER_CURVE_TO: 'bezierCurveTo', 		// Bezier cubic curve
 31 	CSPLINE_THRU: 'splineThru',				// Catmull-rom spline
 32 	ARC: 'arc',								// Circle
 33 	ELLIPSE: 'ellipse'
 34 };
 35 
 36 // TODO Clean up PATH API
 37 
 38 // Create path using straight lines to connect all points
 39 // - vectors: array of Vector2
 40 
 41 THREE.Path.prototype.fromPoints = function ( vectors ) {
 42 
 43 	this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
 44 
 45 	for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
 46 
 47 		this.lineTo( vectors[ v ].x, vectors[ v ].y );
 48 
 49 	};
 50 
 51 };
 52 
 53 // startPath() endPath()?
 54 
 55 THREE.Path.prototype.moveTo = function ( x, y ) {
 56 
 57 	var args = Array.prototype.slice.call( arguments );
 58 	this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
 59 
 60 };
 61 
 62 THREE.Path.prototype.lineTo = function ( x, y ) {
 63 
 64 	var args = Array.prototype.slice.call( arguments );
 65 
 66 	var lastargs = this.actions[ this.actions.length - 1 ].args;
 67 
 68 	var x0 = lastargs[ lastargs.length - 2 ];
 69 	var y0 = lastargs[ lastargs.length - 1 ];
 70 
 71 	var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
 72 	this.curves.push( curve );
 73 
 74 	this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
 75 
 76 };
 77 
 78 THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
 79 
 80 	var args = Array.prototype.slice.call( arguments );
 81 
 82 	var lastargs = this.actions[ this.actions.length - 1 ].args;
 83 
 84 	var x0 = lastargs[ lastargs.length - 2 ];
 85 	var y0 = lastargs[ lastargs.length - 1 ];
 86 
 87 	var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
 88 												new THREE.Vector2( aCPx, aCPy ),
 89 												new THREE.Vector2( aX, aY ) );
 90 	this.curves.push( curve );
 91 
 92 	this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
 93 
 94 };
 95 
 96 THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
 97                                                aCP2x, aCP2y,
 98                                                aX, aY ) {
 99 
100 	var args = Array.prototype.slice.call( arguments );
101 
102 	var lastargs = this.actions[ this.actions.length - 1 ].args;
103 
104 	var x0 = lastargs[ lastargs.length - 2 ];
105 	var y0 = lastargs[ lastargs.length - 1 ];
106 
107 	var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
108 											new THREE.Vector2( aCP1x, aCP1y ),
109 											new THREE.Vector2( aCP2x, aCP2y ),
110 											new THREE.Vector2( aX, aY ) );
111 	this.curves.push( curve );
112 
113 	this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
114 
115 };
116 
117 THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
118 
119 	var args = Array.prototype.slice.call( arguments );
120 	var lastargs = this.actions[ this.actions.length - 1 ].args;
121 
122 	var x0 = lastargs[ lastargs.length - 2 ];
123 	var y0 = lastargs[ lastargs.length - 1 ];
124 //---
125 	var npts = [ new THREE.Vector2( x0, y0 ) ];
126 	Array.prototype.push.apply( npts, pts );
127 
128 	var curve = new THREE.SplineCurve( npts );
129 	this.curves.push( curve );
130 
131 	this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
132 
133 };
134 
135 // FUTURE: Change the API or follow canvas API?
136 
137 THREE.Path.prototype.arc = function ( aX, aY, aRadius,
138 									  aStartAngle, aEndAngle, aClockwise ) {
139 
140 	var lastargs = this.actions[ this.actions.length - 1].args;
141 	var x0 = lastargs[ lastargs.length - 2 ];
142 	var y0 = lastargs[ lastargs.length - 1 ];
143 
144 	this.absarc(aX + x0, aY + y0, aRadius,
145 		aStartAngle, aEndAngle, aClockwise );
146 	
147  };
148 
149  THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
150 									  aStartAngle, aEndAngle, aClockwise ) {
151 	this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
152  };
153  
154 THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
155 									  aStartAngle, aEndAngle, aClockwise ) {
156 
157 	var lastargs = this.actions[ this.actions.length - 1].args;
158 	var x0 = lastargs[ lastargs.length - 2 ];
159 	var y0 = lastargs[ lastargs.length - 1 ];
160 
161 	this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
162 		aStartAngle, aEndAngle, aClockwise );
163 
164  };
165  
166 
167 THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
168 									  aStartAngle, aEndAngle, aClockwise ) {
169 
170 	var args = Array.prototype.slice.call( arguments );
171 	var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
172 									aStartAngle, aEndAngle, aClockwise );
173 	this.curves.push( curve );
174 
175 	var lastPoint = curve.getPoint(aClockwise ? 1 : 0);
176 	args.push(lastPoint.x);
177 	args.push(lastPoint.y);
178 
179 	this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
180 
181  };
182 
183 THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
184 
185 	if ( ! divisions ) divisions = 40;
186 
187 	var points = [];
188 
189 	for ( var i = 0; i < divisions; i ++ ) {
190 
191 		points.push( this.getPoint( i / divisions ) );
192 
193 		//if( !this.getPoint( i / divisions ) ) throw "DIE";
194 
195 	}
196 
197 	// if ( closedPath ) {
198 	//
199 	// 	points.push( points[ 0 ] );
200 	//
201 	// }
202 
203 	return points;
204 
205 };
206 
207 /* Return an array of vectors based on contour of the path */
208 
209 THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
210 
211 	if (this.useSpacedPoints) {
212 		console.log('tata');
213 		return this.getSpacedPoints( divisions, closedPath );
214 	}
215 
216 	divisions = divisions || 12;
217 
218 	var points = [];
219 
220 	var i, il, item, action, args;
221 	var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
222 		laste, j,
223 		t, tx, ty;
224 
225 	for ( i = 0, il = this.actions.length; i < il; i ++ ) {
226 
227 		item = this.actions[ i ];
228 
229 		action = item.action;
230 		args = item.args;
231 
232 		switch( action ) {
233 
234 		case THREE.PathActions.MOVE_TO:
235 
236 			points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
237 
238 			break;
239 
240 		case THREE.PathActions.LINE_TO:
241 
242 			points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
243 
244 			break;
245 
246 		case THREE.PathActions.QUADRATIC_CURVE_TO:
247 
248 			cpx  = args[ 2 ];
249 			cpy  = args[ 3 ];
250 
251 			cpx1 = args[ 0 ];
252 			cpy1 = args[ 1 ];
253 
254 			if ( points.length > 0 ) {
255 
256 				laste = points[ points.length - 1 ];
257 
258 				cpx0 = laste.x;
259 				cpy0 = laste.y;
260 
261 			} else {
262 
263 				laste = this.actions[ i - 1 ].args;
264 
265 				cpx0 = laste[ laste.length - 2 ];
266 				cpy0 = laste[ laste.length - 1 ];
267 
268 			}
269 
270 			for ( j = 1; j <= divisions; j ++ ) {
271 
272 				t = j / divisions;
273 
274 				tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
275 				ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
276 
277 				points.push( new THREE.Vector2( tx, ty ) );
278 
279 		  	}
280 
281 			break;
282 
283 		case THREE.PathActions.BEZIER_CURVE_TO:
284 
285 			cpx  = args[ 4 ];
286 			cpy  = args[ 5 ];
287 
288 			cpx1 = args[ 0 ];
289 			cpy1 = args[ 1 ];
290 
291 			cpx2 = args[ 2 ];
292 			cpy2 = args[ 3 ];
293 
294 			if ( points.length > 0 ) {
295 
296 				laste = points[ points.length - 1 ];
297 
298 				cpx0 = laste.x;
299 				cpy0 = laste.y;
300 
301 			} else {
302 
303 				laste = this.actions[ i - 1 ].args;
304 
305 				cpx0 = laste[ laste.length - 2 ];
306 				cpy0 = laste[ laste.length - 1 ];
307 
308 			}
309 
310 
311 			for ( j = 1; j <= divisions; j ++ ) {
312 
313 				t = j / divisions;
314 
315 				tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
316 				ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
317 
318 				points.push( new THREE.Vector2( tx, ty ) );
319 
320 			}
321 
322 			break;
323 
324 		case THREE.PathActions.CSPLINE_THRU:
325 
326 			laste = this.actions[ i - 1 ].args;
327 
328 			var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
329 			var spts = [ last ];
330 
331 			var n = divisions * args[ 0 ].length;
332 
333 			spts = spts.concat( args[ 0 ] );
334 
335 			var spline = new THREE.SplineCurve( spts );
336 
337 			for ( j = 1; j <= n; j ++ ) {
338 
339 				points.push( spline.getPointAt( j / n ) ) ;
340 
341 			}
342 
343 			break;
344 
345 		case THREE.PathActions.ARC:
346 
347 			var aX = args[ 0 ], aY = args[ 1 ],
348 				aRadius = args[ 2 ],
349 				aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
350 				aClockwise = !!args[ 5 ];
351 
352 			var deltaAngle = aEndAngle - aStartAngle;
353 			var angle;
354 			var tdivisions = divisions * 2;
355 
356 			for ( j = 1; j <= tdivisions; j ++ ) {
357 
358 				t = j / tdivisions;
359 
360 				if ( ! aClockwise ) {
361 
362 					t = 1 - t;
363 
364 				}
365 
366 				angle = aStartAngle + t * deltaAngle;
367 
368 				tx = aX + aRadius * Math.cos( angle );
369 				ty = aY + aRadius * Math.sin( angle );
370 
371 				//console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
372 
373 				points.push( new THREE.Vector2( tx, ty ) );
374 
375 			}
376 
377 			//console.log(points);
378 
379 		  break;
380 		  
381 		case THREE.PathActions.ELLIPSE:
382 
383 			var aX = args[ 0 ], aY = args[ 1 ],
384 				xRadius = args[ 2 ],
385 				yRadius = args[ 3 ],
386 				aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
387 				aClockwise = !!args[ 6 ];
388 
389 
390 			var deltaAngle = aEndAngle - aStartAngle;
391 			var angle;
392 			var tdivisions = divisions * 2;
393 
394 			for ( j = 1; j <= tdivisions; j ++ ) {
395 
396 				t = j / tdivisions;
397 
398 				if ( ! aClockwise ) {
399 
400 					t = 1 - t;
401 
402 				}
403 
404 				angle = aStartAngle + t * deltaAngle;
405 
406 				tx = aX + xRadius * Math.cos( angle );
407 				ty = aY + yRadius * Math.sin( angle );
408 
409 				//console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
410 
411 				points.push( new THREE.Vector2( tx, ty ) );
412 
413 			}
414 
415 			//console.log(points);
416 
417 		  break;
418 
419 		} // end switch
420 
421 	}
422 
423 
424 
425 	// Normalize to remove the closing point by default.
426 	var lastPoint = points[ points.length - 1];
427 	var EPSILON = 0.0000000001;
428 	if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
429              Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
430 		points.splice( points.length - 1, 1);
431 	if ( closedPath ) {
432 
433 		points.push( points[ 0 ] );
434 
435 	}
436 
437 	return points;
438 
439 };
440 
441 // Breaks path into shapes
442 
443 THREE.Path.prototype.toShapes = function() {
444 
445 	var i, il, item, action, args;
446 
447 	var subPaths = [], lastPath = new THREE.Path();
448 
449 	for ( i = 0, il = this.actions.length; i < il; i ++ ) {
450 
451 		item = this.actions[ i ];
452 
453 		args = item.args;
454 		action = item.action;
455 
456 		if ( action == THREE.PathActions.MOVE_TO ) {
457 
458 			if ( lastPath.actions.length != 0 ) {
459 
460 				subPaths.push( lastPath );
461 				lastPath = new THREE.Path();
462 
463 			}
464 
465 		}
466 
467 		lastPath[ action ].apply( lastPath, args );
468 
469 	}
470 
471 	if ( lastPath.actions.length != 0 ) {
472 
473 		subPaths.push( lastPath );
474 
475 	}
476 
477 	// console.log(subPaths);
478 
479 	if ( subPaths.length == 0 ) return [];
480 
481 	var tmpPath, tmpShape, shapes = [];
482 
483 	var holesFirst = !THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
484 	// console.log("Holes first", holesFirst);
485 
486 	if ( subPaths.length == 1) {
487 		tmpPath = subPaths[0];
488 		tmpShape = new THREE.Shape();
489 		tmpShape.actions = tmpPath.actions;
490 		tmpShape.curves = tmpPath.curves;
491 		shapes.push( tmpShape );
492 		return shapes;
493 	};
494 
495 	if ( holesFirst ) {
496 
497 		tmpShape = new THREE.Shape();
498 
499 		for ( i = 0, il = subPaths.length; i < il; i ++ ) {
500 
501 			tmpPath = subPaths[ i ];
502 
503 			if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
504 
505 				tmpShape.actions = tmpPath.actions;
506 				tmpShape.curves = tmpPath.curves;
507 
508 				shapes.push( tmpShape );
509 				tmpShape = new THREE.Shape();
510 
511 				//console.log('cw', i);
512 
513 			} else {
514 
515 				tmpShape.holes.push( tmpPath );
516 
517 				//console.log('ccw', i);
518 
519 			}
520 
521 		}
522 
523 	} else {
524 
525 		// Shapes first
526 
527 		for ( i = 0, il = subPaths.length; i < il; i ++ ) {
528 
529 			tmpPath = subPaths[ i ];
530 
531 			if ( THREE.Shape.Utils.isClockWise( tmpPath.getPoints() ) ) {
532 
533 
534 				if ( tmpShape ) shapes.push( tmpShape );
535 
536 				tmpShape = new THREE.Shape();
537 				tmpShape.actions = tmpPath.actions;
538 				tmpShape.curves = tmpPath.curves;
539 
540 			} else {
541 
542 				tmpShape.holes.push( tmpPath );
543 
544 			}
545 
546 		}
547 
548 		shapes.push( tmpShape );
549 
550 	}
551 
552 	//console.log("shape", shapes);
553 
554 	return shapes;
555 
556 };
557 

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