1 /**
  2  * @author mikael emtinger / http://gomo.se/
  3  * @author mrdoob / http://mrdoob.com/
  4  * @author alteredq / http://alteredqualia.com/
  5  * @author khang duong
  6  * @author erik kitson
  7  */
  8 
  9 /**@constructor*/
 10 THREE.KeyFrameAnimation = function( root, data, JITCompile ) {
 11 
 12 	this.root = root;
 13 	this.data = THREE.AnimationHandler.get( data );
 14 	this.hierarchy = THREE.AnimationHandler.parse( root );
 15 	this.currentTime = 0;
 16 	this.timeScale = 0.001;
 17 	this.isPlaying = false;
 18 	this.isPaused = true;
 19 	this.loop = true;
 20 	this.JITCompile = JITCompile !== undefined ? JITCompile : true;
 21 
 22 	// initialize to first keyframes
 23 
 24 	for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
 25 
 26 		var keys = this.data.hierarchy[h].keys,
 27 			sids = this.data.hierarchy[h].sids,
 28 			obj = this.hierarchy[h];
 29 
 30 		if ( keys.length && sids ) {
 31 
 32 			for ( var s = 0; s < sids.length; s++ ) {
 33 
 34 				var sid = sids[ s ],
 35 					next = this.getNextKeyWith( sid, h, 0 );
 36 
 37 				if ( next ) {
 38 
 39 					next.apply( sid );
 40 
 41 				}
 42 
 43 			}
 44 
 45 			obj.matrixAutoUpdate = false;
 46 			this.data.hierarchy[h].node.updateMatrix();
 47 			obj.matrixWorldNeedsUpdate = true;
 48 
 49 		}
 50 
 51 	}
 52 
 53 };
 54 
 55 // Play
 56 
 57 THREE.KeyFrameAnimation.prototype.play = function( loop, startTimeMS ) {
 58 
 59 	if( !this.isPlaying ) {
 60 
 61 		this.isPlaying = true;
 62 		this.loop = loop !== undefined ? loop : true;
 63 		this.currentTime = startTimeMS !== undefined ? startTimeMS : 0;
 64 		this.startTimeMs = startTimeMS;
 65 		this.startTime = 10000000;
 66 		this.endTime = -this.startTime;
 67 
 68 
 69 		// reset key cache
 70 
 71 		var h, hl = this.hierarchy.length,
 72 			object,
 73 			node;
 74 
 75 		for ( h = 0; h < hl; h++ ) {
 76 
 77 			object = this.hierarchy[ h ];
 78 			node = this.data.hierarchy[ h ];
 79 			object.useQuaternion = true;
 80 
 81 			if ( node.animationCache === undefined ) {
 82 
 83 				node.animationCache = {};
 84 				node.animationCache.prevKey = null;
 85 				node.animationCache.nextKey = null;
 86 				node.animationCache.originalMatrix = object instanceof THREE.Bone ? object.skinMatrix : object.matrix;
 87 
 88 			}
 89 
 90 			var keys = this.data.hierarchy[h].keys;
 91 
 92 			if (keys.length) {
 93 
 94 				node.animationCache.prevKey = keys[ 0 ];
 95 				node.animationCache.nextKey = keys[ 1 ];
 96 
 97 				this.startTime = Math.min( keys[0].time, this.startTime );
 98 				this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
 99 
100 			}
101 
102 		}
103 
104 		this.update( 0 );
105 
106 	}
107 
108 	this.isPaused = false;
109 
110 	THREE.AnimationHandler.addToUpdate( this );
111 
112 };
113 
114 
115 
116 // Pause
117 
118 THREE.KeyFrameAnimation.prototype.pause = function() {
119 
120 	if( this.isPaused ) {
121 
122 		THREE.AnimationHandler.addToUpdate( this );
123 
124 	} else {
125 
126 		THREE.AnimationHandler.removeFromUpdate( this );
127 
128 	}
129 
130 	this.isPaused = !this.isPaused;
131 
132 };
133 
134 
135 // Stop
136 
137 THREE.KeyFrameAnimation.prototype.stop = function() {
138 
139 	this.isPlaying = false;
140 	this.isPaused  = false;
141 	THREE.AnimationHandler.removeFromUpdate( this );
142 
143 
144 	// reset JIT matrix and remove cache
145 
146 	for ( var h = 0; h < this.data.hierarchy.length; h++ ) {
147         
148         var obj = this.hierarchy[ h ];
149 		var node = this.data.hierarchy[ h ];
150 
151 		if ( node.animationCache !== undefined ) {
152 
153 			var original = node.animationCache.originalMatrix;
154 
155 			if( obj instanceof THREE.Bone ) {
156 
157 				original.copy( obj.skinMatrix );
158 				obj.skinMatrix = original;
159 
160 			} else {
161 
162 				original.copy( obj.matrix );
163 				obj.matrix = original;
164 
165 			}
166 
167 			delete node.animationCache;
168 
169 		}
170 
171 	}
172 
173 };
174 
175 
176 // Update
177 
178 THREE.KeyFrameAnimation.prototype.update = function( deltaTimeMS ) {
179 
180 	// early out
181 
182 	if( !this.isPlaying ) return;
183 
184 
185 	// vars
186 
187 	var prevKey, nextKey;
188 	var object;
189 	var node;
190 	var frame;
191 	var JIThierarchy = this.data.JIT.hierarchy;
192 	var currentTime, unloopedCurrentTime;
193 	var looped;
194 
195 
196 	// update
197 
198 	this.currentTime += deltaTimeMS * this.timeScale;
199 
200 	unloopedCurrentTime = this.currentTime;
201 	currentTime         = this.currentTime = this.currentTime % this.data.length;
202 
203 	// if looped around, the current time should be based on the startTime
204 	if ( currentTime < this.startTimeMs ) {
205 
206 		currentTime = this.currentTime = this.startTimeMs + currentTime;
207 
208 	}
209 
210 	frame               = parseInt( Math.min( currentTime * this.data.fps, this.data.length * this.data.fps ), 10 );
211 	looped 				= currentTime < unloopedCurrentTime;
212 
213 	if ( looped && !this.loop ) {
214 
215 		// Set the animation to the last keyframes and stop
216 		for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
217 
218 			var keys = this.data.hierarchy[h].keys,
219 				sids = this.data.hierarchy[h].sids,
220 				end = keys.length-1,
221 				obj = this.hierarchy[h];
222 
223 			if ( keys.length ) {
224 
225 				for ( var s = 0; s < sids.length; s++ ) {
226 
227 					var sid = sids[ s ],
228 						prev = this.getPrevKeyWith( sid, h, end );
229 
230 					if ( prev ) {
231 						prev.apply( sid );
232 
233 					}
234 
235 				}
236 
237 				this.data.hierarchy[h].node.updateMatrix();
238 				obj.matrixWorldNeedsUpdate = true;
239 
240 			}
241 
242 		}
243 
244 		this.stop();
245 		return;
246 
247 	}
248 
249 	// check pre-infinity
250 	if ( currentTime < this.startTime ) {
251 
252 		return;
253 
254 	}
255 
256 	// update
257 
258 	for ( var h = 0, hl = this.hierarchy.length; h < hl; h++ ) {
259 
260 		object = this.hierarchy[ h ];
261 		node = this.data.hierarchy[ h ];
262 
263 		var keys = node.keys,
264 			animationCache = node.animationCache;
265 
266 		// use JIT?
267 
268 		if ( this.JITCompile && JIThierarchy[ h ][ frame ] !== undefined ) {
269 
270 			if( object instanceof THREE.Bone ) {
271 
272 				object.skinMatrix = JIThierarchy[ h ][ frame ];
273 				object.matrixWorldNeedsUpdate = false;
274 
275 			} else {
276 
277 				object.matrix = JIThierarchy[ h ][ frame ];
278 				object.matrixWorldNeedsUpdate = true;
279 
280 			}
281 
282 		// use interpolation
283 
284 		} else if ( keys.length ) {
285 
286 			// make sure so original matrix and not JIT matrix is set
287 
288 			if ( this.JITCompile && animationCache ) {
289 
290 				if( object instanceof THREE.Bone ) {
291 
292 					object.skinMatrix = animationCache.originalMatrix;
293 
294 				} else {
295 
296 					object.matrix = animationCache.originalMatrix;
297 
298 				}
299 
300 			}
301 
302 			prevKey = animationCache.prevKey;
303 			nextKey = animationCache.nextKey;
304 
305 			if ( prevKey && nextKey ) {
306 
307 				// switch keys?
308 
309 				if ( nextKey.time <= unloopedCurrentTime ) {
310 
311 					// did we loop?
312 
313 					if ( looped && this.loop ) {
314 
315 						prevKey = keys[ 0 ];
316 						nextKey = keys[ 1 ];
317 
318 						while ( nextKey.time < currentTime ) {
319 
320 							prevKey = nextKey;
321 							nextKey = keys[ prevKey.index + 1 ];
322 
323 						}
324 
325 					} else if ( !looped ) {
326 
327 						var lastIndex = keys.length - 1;
328 
329 						while ( nextKey.time < currentTime && nextKey.index !== lastIndex ) {
330 
331 							prevKey = nextKey;
332 							nextKey = keys[ prevKey.index + 1 ];
333 
334 						}
335 
336 					}
337 
338 					animationCache.prevKey = prevKey;
339 					animationCache.nextKey = nextKey;
340 
341 				}
342                 if(nextKey.time >= currentTime)
343                     prevKey.interpolate( nextKey, currentTime );
344                 else
345                     prevKey.interpolate( nextKey, nextKey.time);
346 
347 			}
348 
349 			this.data.hierarchy[h].node.updateMatrix();
350 			object.matrixWorldNeedsUpdate = true;
351 
352 		}
353 
354 	}
355 
356 	// update JIT?
357 
358 	if ( this.JITCompile ) {
359 
360 		if ( JIThierarchy[ 0 ][ frame ] === undefined ) {
361 
362 			this.hierarchy[ 0 ].updateMatrixWorld( true );
363 
364 			for ( var h = 0; h < this.hierarchy.length; h++ ) {
365 
366 				if( this.hierarchy[ h ] instanceof THREE.Bone ) {
367 
368 					JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].skinMatrix.clone();
369 
370 				} else {
371 
372 					JIThierarchy[ h ][ frame ] = this.hierarchy[ h ].matrix.clone();
373 
374 				}
375 
376 			}
377 
378 		}
379 
380 	}
381 
382 };
383 
384 // Get next key with
385 
386 THREE.KeyFrameAnimation.prototype.getNextKeyWith = function( sid, h, key ) {
387 
388 	var keys = this.data.hierarchy[ h ].keys;
389 	key = key % keys.length;
390 
391 	for ( ; key < keys.length; key++ ) {
392 
393 		if ( keys[ key ].hasTarget( sid ) ) {
394 
395 			return keys[ key ];
396 
397 		}
398 
399 	}
400 
401 	return keys[ 0 ];
402 
403 };
404 
405 // Get previous key with
406 
407 THREE.KeyFrameAnimation.prototype.getPrevKeyWith = function( sid, h, key ) {
408 
409 	var keys = this.data.hierarchy[ h ].keys;
410 	key = key >= 0 ? key : key + keys.length;
411 
412 	for ( ; key >= 0; key-- ) {
413 
414 		if ( keys[ key ].hasTarget( sid ) ) {
415 
416 			return keys[ key ];
417 
418 		}
419 
420 	}
421 
422 	return keys[ keys.length - 1 ];
423 
424 };
425 

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