1 /**
2 * @author alteredq / http://alteredqualia.com/
3 */
4
5 /**@constructor*/
6 THREE.MorphBlendMesh = function( geometry, material ) {
7
8 THREE.Mesh.call( this, geometry, material );
9
10 this.animationsMap = {};
11 this.animationsList = [];
12
13 // prepare default animation
14 // (all frames played together in 1 second)
15
16 var numFrames = this.geometry.morphTargets.length;
17
18 var name = "__default";
19
20 var startFrame = 0;
21 var endFrame = numFrames - 1;
22
23 var fps = numFrames / 1;
24
25 this.createAnimation( name, startFrame, endFrame, fps );
26 this.setAnimationWeight( name, 1 );
27
28 };
29
30 THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
31
32 THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
33
34 var animation = {
35
36 startFrame: start,
37 endFrame: end,
38
39 length: end - start + 1,
40
41 fps: fps,
42 duration: ( end - start ) / fps,
43
44 lastFrame: 0,
45 currentFrame: 0,
46
47 active: false,
48
49 time: 0,
50 direction: 1,
51 weight: 1,
52
53 directionBackwards: false,
54 mirroredLoop: false
55
56 };
57
58 this.animationsMap[ name ] = animation;
59 this.animationsList.push( animation );
60
61 };
62
63 THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
64
65 var pattern = /([a-z]+)(\d+)/;
66
67 var firstAnimation, frameRanges = {};
68
69 var geometry = this.geometry;
70
71 for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
72
73 var morph = geometry.morphTargets[ i ];
74 var chunks = morph.name.match( pattern );
75
76 if ( chunks && chunks.length > 1 ) {
77
78 var name = chunks[ 1 ];
79 var num = chunks[ 2 ];
80
81 if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: -Infinity };
82
83 var range = frameRanges[ name ];
84
85 if ( i < range.start ) range.start = i;
86 if ( i > range.end ) range.end = i;
87
88 if ( ! firstAnimation ) firstAnimation = name;
89
90 }
91
92 }
93
94 for ( var name in frameRanges ) {
95
96 var range = frameRanges[ name ];
97 this.createAnimation( name, range.start, range.end, fps );
98
99 }
100
101 this.firstAnimation = firstAnimation;
102
103 };
104
105 THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
106
107 var animation = this.animationsMap[ name ];
108
109 if ( animation ) {
110
111 animation.direction = 1;
112 animation.directionBackwards = false;
113
114 }
115
116 };
117
118 THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
119
120 var animation = this.animationsMap[ name ];
121
122 if ( animation ) {
123
124 animation.direction = -1;
125 animation.directionBackwards = true;
126
127 }
128
129 };
130
131 THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
132
133 var animation = this.animationsMap[ name ];
134
135 if ( animation ) {
136
137 animation.fps = fps;
138 animation.duration = ( animation.end - animation.start ) / animation.fps;
139
140 }
141
142 };
143
144 THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
145
146 var animation = this.animationsMap[ name ];
147
148 if ( animation ) {
149
150 animation.duration = duration;
151 animation.fps = ( animation.end - animation.start ) / animation.duration;
152
153 }
154
155 };
156
157 THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
158
159 var animation = this.animationsMap[ name ];
160
161 if ( animation ) {
162
163 animation.weight = weight;
164
165 }
166
167 };
168
169 THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
170
171 var animation = this.animationsMap[ name ];
172
173 if ( animation ) {
174
175 animation.time = time;
176
177 }
178
179 };
180
181 THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
182
183 var time = 0;
184
185 var animation = this.animationsMap[ name ];
186
187 if ( animation ) {
188
189 time = animation.time;
190
191 }
192
193 return time;
194
195 };
196
197 THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
198
199 var duration = -1;
200
201 var animation = this.animationsMap[ name ];
202
203 if ( animation ) {
204
205 duration = animation.duration;
206
207 }
208
209 return duration;
210
211 };
212
213 THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
214
215 var animation = this.animationsMap[ name ];
216
217 if ( animation ) {
218
219 animation.time = 0;
220 animation.active = true;
221
222 } else {
223
224 console.warn( "animation[" + name + "] undefined" );
225
226 }
227
228 };
229
230 THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
231
232 var animation = this.animationsMap[ name ];
233
234 if ( animation ) {
235
236 animation.active = false;
237
238 }
239
240 };
241
242 THREE.MorphBlendMesh.prototype.update = function ( delta ) {
243
244 for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
245
246 var animation = this.animationsList[ i ];
247
248 if ( ! animation.active ) continue;
249
250 var frameTime = animation.duration / animation.length;
251
252 animation.time += animation.direction * delta;
253
254 if ( animation.mirroredLoop ) {
255
256 if ( animation.time > animation.duration || animation.time < 0 ) {
257
258 animation.direction *= -1;
259
260 if ( animation.time > animation.duration ) {
261
262 animation.time = animation.duration;
263 animation.directionBackwards = true;
264
265 }
266
267 if ( animation.time < 0 ) {
268
269 animation.time = 0;
270 animation.directionBackwards = false;
271
272 }
273
274 }
275
276 } else {
277
278 animation.time = animation.time % animation.duration;
279
280 if ( animation.time < 0 ) animation.time += animation.duration;
281
282 }
283
284 var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
285 var weight = animation.weight;
286
287 if ( keyframe !== animation.currentFrame ) {
288
289 this.morphTargetInfluences[ animation.lastFrame ] = 0;
290 this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
291
292 this.morphTargetInfluences[ keyframe ] = 0;
293
294 animation.lastFrame = animation.currentFrame;
295 animation.currentFrame = keyframe;
296
297 }
298
299 var mix = ( animation.time % frameTime ) / frameTime;
300
301 if ( animation.directionBackwards ) mix = 1 - mix;
302
303 this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
304 this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
305
306 }
307
308 };
309
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