1 /**
2 * Spline from Tween.js, slightly optimized (and trashed)
3 * http://sole.github.com/tween.js/examples/05_spline.html
4 *
5 * @author mrdoob / http://mrdoob.com/
6 * @author alteredq / http://alteredqualia.com/
7 */
8
9 /**@constructor*/
10 THREE.Spline = function ( points ) {
11
12 this.points = points;
13
14 var c = [], v3 = { x: 0, y: 0, z: 0 },
15 point, intPoint, weight, w2, w3,
16 pa, pb, pc, pd;
17
18 this.initFromArray = function( a ) {
19
20 this.points = [];
21
22 for ( var i = 0; i < a.length; i++ ) {
23
24 this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
25
26 }
27
28 };
29
30 this.getPoint = function ( k ) {
31
32 point = ( this.points.length - 1 ) * k;
33 intPoint = Math.floor( point );
34 weight = point - intPoint;
35
36 c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
37 c[ 1 ] = intPoint;
38 c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
39 c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
40
41 pa = this.points[ c[ 0 ] ];
42 pb = this.points[ c[ 1 ] ];
43 pc = this.points[ c[ 2 ] ];
44 pd = this.points[ c[ 3 ] ];
45
46 w2 = weight * weight;
47 w3 = weight * w2;
48
49 v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
50 v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
51 v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
52
53 return v3;
54
55 };
56
57 this.getControlPointsArray = function () {
58
59 var i, p, l = this.points.length,
60 coords = [];
61
62 for ( i = 0; i < l; i ++ ) {
63
64 p = this.points[ i ];
65 coords[ i ] = [ p.x, p.y, p.z ];
66
67 }
68
69 return coords;
70
71 };
72
73 // approximate length by summing linear segments
74
75 this.getLength = function ( nSubDivisions ) {
76
77 var i, index, nSamples, position,
78 point = 0, intPoint = 0, oldIntPoint = 0,
79 oldPosition = new THREE.Vector3(),
80 tmpVec = new THREE.Vector3(),
81 chunkLengths = [],
82 totalLength = 0;
83
84 // first point has 0 length
85
86 chunkLengths[ 0 ] = 0;
87
88 if ( !nSubDivisions ) nSubDivisions = 100;
89
90 nSamples = this.points.length * nSubDivisions;
91
92 oldPosition.copy( this.points[ 0 ] );
93
94 for ( i = 1; i < nSamples; i ++ ) {
95
96 index = i / nSamples;
97
98 position = this.getPoint( index );
99 tmpVec.copy( position );
100
101 totalLength += tmpVec.distanceTo( oldPosition );
102
103 oldPosition.copy( position );
104
105 point = ( this.points.length - 1 ) * index;
106 intPoint = Math.floor( point );
107
108 if ( intPoint != oldIntPoint ) {
109
110 chunkLengths[ intPoint ] = totalLength;
111 oldIntPoint = intPoint;
112
113 }
114
115 }
116
117 // last point ends with total length
118
119 chunkLengths[ chunkLengths.length ] = totalLength;
120
121 return { chunks: chunkLengths, total: totalLength };
122
123 };
124
125 this.reparametrizeByArcLength = function ( samplingCoef ) {
126
127 var i, j,
128 index, indexCurrent, indexNext,
129 linearDistance, realDistance,
130 sampling, position,
131 newpoints = [],
132 tmpVec = new THREE.Vector3(),
133 sl = this.getLength();
134
135 newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
136
137 for ( i = 1; i < this.points.length; i++ ) {
138
139 //tmpVec.copy( this.points[ i - 1 ] );
140 //linearDistance = tmpVec.distanceTo( this.points[ i ] );
141
142 realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
143
144 sampling = Math.ceil( samplingCoef * realDistance / sl.total );
145
146 indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
147 indexNext = i / ( this.points.length - 1 );
148
149 for ( j = 1; j < sampling - 1; j++ ) {
150
151 index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
152
153 position = this.getPoint( index );
154 newpoints.push( tmpVec.copy( position ).clone() );
155
156 }
157
158 newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
159
160 }
161
162 this.points = newpoints;
163
164 };
165
166 // Catmull-Rom
167
168 function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
169
170 var v0 = ( p2 - p0 ) * 0.5,
171 v1 = ( p3 - p1 ) * 0.5;
172
173 return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
174
175 };
176
177 };
178
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