1 /**
2 * @author alteredq / http://alteredqualia.com/
3 */
4
5 /**@constructor*/
6 THREE.Loader = function ( showStatus ) {
7
8 this.showStatus = showStatus;
9 this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
10
11 this.onLoadStart = function () {};
12 this.onLoadProgress = function () {};
13 this.onLoadComplete = function () {};
14
15 };
16
17 THREE.Loader.prototype = {
18
19 constructor: THREE.Loader,
20
21 crossOrigin: 'anonymous',
22
23 addStatusElement: function () {
24
25 var e = document.createElement( "div" );
26
27 e.style.position = "absolute";
28 e.style.right = "0px";
29 e.style.top = "0px";
30 e.style.fontSize = "0.8em";
31 e.style.textAlign = "left";
32 e.style.background = "rgba(0,0,0,0.25)";
33 e.style.color = "#fff";
34 e.style.width = "120px";
35 e.style.padding = "0.5em 0.5em 0.5em 0.5em";
36 e.style.zIndex = 1000;
37
38 e.innerHTML = "Loading ...";
39
40 return e;
41
42 },
43
44 updateProgress: function ( progress ) {
45
46 var message = "Loaded ";
47
48 if ( progress.total ) {
49
50 message += ( 100 * progress.loaded / progress.total ).toFixed(0) + "%";
51
52
53 } else {
54
55 message += ( progress.loaded / 1000 ).toFixed(2) + " KB";
56
57 }
58
59 this.statusDomElement.innerHTML = message;
60
61 },
62
63 extractUrlBase: function ( url ) {
64
65 var parts = url.split( '/' );
66 parts.pop();
67 return ( parts.length < 1 ? '.' : parts.join( '/' ) ) + '/';
68
69 },
70
71 initMaterials: function ( materials, texturePath ) {
72
73 var array = [];
74
75 for ( var i = 0; i < materials.length; ++ i ) {
76
77 array[ i ] = THREE.Loader.prototype.createMaterial( materials[ i ], texturePath );
78
79 }
80
81 return array;
82
83 },
84
85 needsTangents: function ( materials ) {
86
87 for( var i = 0, il = materials.length; i < il; i ++ ) {
88
89 var m = materials[ i ];
90
91 if ( m instanceof THREE.ShaderMaterial ) return true;
92
93 }
94
95 return false;
96
97 },
98
99 createMaterial: function ( m, texturePath ) {
100
101 var _this = this;
102
103 function is_pow2( n ) {
104
105 var l = Math.log( n ) / Math.LN2;
106 return Math.floor( l ) == l;
107
108 }
109
110 function nearest_pow2( n ) {
111
112 var l = Math.log( n ) / Math.LN2;
113 return Math.pow( 2, Math.round( l ) );
114
115 }
116
117 function load_image( where, url ) {
118
119 var image = new Image();
120
121 image.onload = function () {
122
123 if ( !is_pow2( this.width ) || !is_pow2( this.height ) ) {
124
125 var width = nearest_pow2( this.width );
126 var height = nearest_pow2( this.height );
127
128 where.image.width = width;
129 where.image.height = height;
130 where.image.getContext( '2d' ).drawImage( this, 0, 0, width, height );
131
132 } else {
133
134 where.image = this;
135
136 }
137
138 where.needsUpdate = true;
139
140 };
141
142 image.crossOrigin = _this.crossOrigin;
143 image.src = url;
144
145 }
146
147 function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
148
149 var isCompressed = sourceFile.toLowerCase().endsWith( ".dds" );
150 var fullPath = texturePath + "/" + sourceFile;
151
152 if ( isCompressed ) {
153
154 var texture = THREE.ImageUtils.loadCompressedTexture( fullPath );
155
156 where[ name ] = texture;
157
158 } else {
159
160 var texture = document.createElement( 'canvas' );
161
162 where[ name ] = new THREE.Texture( texture );
163
164 }
165
166 where[ name ].sourceFile = sourceFile;
167
168 if( repeat ) {
169
170 where[ name ].repeat.set( repeat[ 0 ], repeat[ 1 ] );
171
172 if ( repeat[ 0 ] !== 1 ) where[ name ].wrapS = THREE.RepeatWrapping;
173 if ( repeat[ 1 ] !== 1 ) where[ name ].wrapT = THREE.RepeatWrapping;
174
175 }
176
177 if ( offset ) {
178
179 where[ name ].offset.set( offset[ 0 ], offset[ 1 ] );
180
181 }
182
183 if ( wrap ) {
184
185 var wrapMap = {
186 "repeat": THREE.RepeatWrapping,
187 "mirror": THREE.MirroredRepeatWrapping
188 }
189
190 if ( wrapMap[ wrap[ 0 ] ] !== undefined ) where[ name ].wrapS = wrapMap[ wrap[ 0 ] ];
191 if ( wrapMap[ wrap[ 1 ] ] !== undefined ) where[ name ].wrapT = wrapMap[ wrap[ 1 ] ];
192
193 }
194
195 if ( anisotropy ) {
196
197 where[ name ].anisotropy = anisotropy;
198
199 }
200
201 if ( ! isCompressed ) {
202
203 load_image( where[ name ], fullPath );
204
205 }
206
207 }
208
209 function rgb2hex( rgb ) {
210
211 return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
212
213 }
214
215 // defaults
216
217 var mtype = "MeshLambertMaterial";
218 var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
219
220 // parameters from model file
221
222 if ( m.shading ) {
223
224 var shading = m.shading.toLowerCase();
225
226 if ( shading === "phong" ) mtype = "MeshPhongMaterial";
227 else if ( shading === "basic" ) mtype = "MeshBasicMaterial";
228
229 }
230
231 if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
232
233 mpars.blending = THREE[ m.blending ];
234
235 }
236
237 if ( m.transparent !== undefined || m.opacity < 1.0 ) {
238
239 mpars.transparent = m.transparent;
240
241 }
242
243 if ( m.depthTest !== undefined ) {
244
245 mpars.depthTest = m.depthTest;
246
247 }
248
249 if ( m.depthWrite !== undefined ) {
250
251 mpars.depthWrite = m.depthWrite;
252
253 }
254
255 if ( m.visible !== undefined ) {
256
257 mpars.visible = m.visible;
258
259 }
260
261 if ( m.flipSided !== undefined ) {
262
263 mpars.side = THREE.BackSide;
264
265 }
266
267 if ( m.doubleSided !== undefined ) {
268
269 mpars.side = THREE.DoubleSide;
270
271 }
272
273 if ( m.wireframe !== undefined ) {
274
275 mpars.wireframe = m.wireframe;
276
277 }
278
279 if ( m.vertexColors !== undefined ) {
280
281 if ( m.vertexColors === "face" ) {
282
283 mpars.vertexColors = THREE.FaceColors;
284
285 } else if ( m.vertexColors ) {
286
287 mpars.vertexColors = THREE.VertexColors;
288
289 }
290
291 }
292
293 // colors
294
295 if ( m.colorDiffuse ) {
296
297 mpars.color = rgb2hex( m.colorDiffuse );
298
299 } else if ( m.DbgColor ) {
300
301 mpars.color = m.DbgColor;
302
303 }
304
305 if ( m.colorSpecular ) {
306
307 mpars.specular = rgb2hex( m.colorSpecular );
308
309 }
310
311 if ( m.colorAmbient ) {
312
313 mpars.ambient = rgb2hex( m.colorAmbient );
314
315 }
316
317 // modifiers
318
319 if ( m.transparency ) {
320
321 mpars.opacity = m.transparency;
322
323 }
324
325 if ( m.specularCoef ) {
326
327 mpars.shininess = m.specularCoef;
328
329 }
330
331 // textures
332
333 if ( m.mapDiffuse && texturePath ) {
334
335 create_texture( mpars, "map", m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
336
337 }
338
339 if ( m.mapLight && texturePath ) {
340
341 create_texture( mpars, "lightMap", m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
342
343 }
344
345 if ( m.mapBump && texturePath ) {
346
347 create_texture( mpars, "bumpMap", m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
348
349 }
350
351 if ( m.mapNormal && texturePath ) {
352
353 create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
354
355 }
356
357 if ( m.mapSpecular && texturePath ) {
358
359 create_texture( mpars, "specularMap", m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
360
361 }
362
363 //
364
365 if ( m.mapBumpScale ) {
366
367 mpars.bumpScale = m.mapBumpScale;
368
369 }
370
371 // special case for normal mapped material
372
373 if ( m.mapNormal ) {
374
375 var shader = THREE.ShaderUtils.lib[ "normal" ];
376 var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
377
378 uniforms[ "tNormal" ].value = mpars.normalMap;
379
380 if ( m.mapNormalFactor ) {
381
382 uniforms[ "uNormalScale" ].value.set( m.mapNormalFactor, m.mapNormalFactor );
383
384 }
385
386 if ( mpars.map ) {
387
388 uniforms[ "tDiffuse" ].value = mpars.map;
389 uniforms[ "enableDiffuse" ].value = true;
390
391 }
392
393 if ( mpars.specularMap ) {
394
395 uniforms[ "tSpecular" ].value = mpars.specularMap;
396 uniforms[ "enableSpecular" ].value = true;
397
398 }
399
400 if ( mpars.lightMap ) {
401
402 uniforms[ "tAO" ].value = mpars.lightMap;
403 uniforms[ "enableAO" ].value = true;
404
405 }
406
407 // for the moment don't handle displacement texture
408
409 uniforms[ "uDiffuseColor" ].value.setHex( mpars.color );
410 uniforms[ "uSpecularColor" ].value.setHex( mpars.specular );
411 uniforms[ "uAmbientColor" ].value.setHex( mpars.ambient );
412
413 uniforms[ "uShininess" ].value = mpars.shininess;
414
415 if ( mpars.opacity !== undefined ) {
416
417 uniforms[ "uOpacity" ].value = mpars.opacity;
418
419 }
420
421 var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
422 var material = new THREE.ShaderMaterial( parameters );
423
424 } else {
425
426 var material = new THREE[ mtype ]( mpars );
427
428 }
429
430 if ( m.DbgName !== undefined ) material.name = m.DbgName;
431
432 return material;
433
434 }
435
436 };
437
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