1 /**
  2  * @author mrdoob / http://mrdoob.com/
  3  * @author alteredq / http://alteredqualia.com/
  4  */
  5 
  6 /**@constructor*/
  7 THREE.JSONLoader = function ( showStatus ) {
  8 
  9 	THREE.Loader.call( this, showStatus );
 10 
 11 	this.withCredentials = false;
 12 
 13 };
 14 
 15 THREE.JSONLoader.prototype = Object.create( THREE.Loader.prototype );
 16 
 17 THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
 18 
 19 	var scope = this;
 20 
 21 	// todo: unify load API to for easier SceneLoader use
 22 
 23 	texturePath = texturePath && ( typeof texturePath === "string" ) ? texturePath : this.extractUrlBase( url );
 24 
 25 	this.onLoadStart();
 26 	this.loadAjaxJSON( this, url, callback, texturePath );
 27 
 28 };
 29 
 30 THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
 31 
 32 	var xhr = new XMLHttpRequest();
 33 
 34 	var length = 0;
 35 
 36 	xhr.withCredentials = this.withCredentials;
 37 
 38 	xhr.onreadystatechange = function () {
 39 
 40 		if ( xhr.readyState === xhr.DONE ) {
 41 
 42 			if ( xhr.status === 200 || xhr.status === 0 ) {
 43 
 44 				if ( xhr.responseText ) {
 45 
 46 					var json = JSON.parse( xhr.responseText );
 47 					context.createModel( json, callback, texturePath );
 48 
 49 				} else {
 50 
 51 					console.warn( "THREE.JSONLoader: [" + url + "] seems to be unreachable or file there is empty" );
 52 
 53 				}
 54 
 55 				// in context of more complex asset initialization
 56 				// do not block on single failed file
 57 				// maybe should go even one more level up
 58 
 59 				context.onLoadComplete();
 60 
 61 			} else {
 62 
 63 				console.error( "THREE.JSONLoader: Couldn't load [" + url + "] [" + xhr.status + "]" );
 64 
 65 			}
 66 
 67 		} else if ( xhr.readyState === xhr.LOADING ) {
 68 
 69 			if ( callbackProgress ) {
 70 
 71 				if ( length === 0 ) {
 72 
 73 					length = xhr.getResponseHeader( "Content-Length" );
 74 
 75 				}
 76 
 77 				callbackProgress( { total: length, loaded: xhr.responseText.length } );
 78 
 79 			}
 80 
 81 		} else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
 82 
 83 			length = xhr.getResponseHeader( "Content-Length" );
 84 
 85 		}
 86 
 87 	};
 88 
 89 	xhr.open( "GET", url, true );
 90 	xhr.send( null );
 91 
 92 };
 93 
 94 THREE.JSONLoader.prototype.createModel = function ( json, callback, texturePath ) {
 95 
 96 	var scope = this,
 97 	geometry = new THREE.Geometry(),
 98 	scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
 99 
100 	parseModel( scale );
101 
102 	parseSkin();
103 	parseMorphing( scale );
104 
105 	geometry.computeCentroids();
106 	geometry.computeFaceNormals();
107 
108 	function parseModel( scale ) {
109 
110 		function isBitSet( value, position ) {
111 
112 			return value & ( 1 << position );
113 
114 		}
115 
116 		var i, j, fi,
117 
118 		offset, zLength, nVertices,
119 
120 		colorIndex, normalIndex, uvIndex, materialIndex,
121 
122 		type,
123 		isQuad,
124 		hasMaterial,
125 		hasFaceUv, hasFaceVertexUv,
126 		hasFaceNormal, hasFaceVertexNormal,
127 		hasFaceColor, hasFaceVertexColor,
128 
129 		vertex, face, color, normal,
130 
131 		uvLayer, uvs, u, v,
132 
133 		faces = json.faces,
134 		vertices = json.vertices,
135 		normals = json.normals,
136 		colors = json.colors,
137 
138 		nUvLayers = 0;
139 
140 		// disregard empty arrays
141 
142 		for ( i = 0; i < json.uvs.length; i++ ) {
143 
144 			if ( json.uvs[ i ].length ) nUvLayers ++;
145 
146 		}
147 
148 		for ( i = 0; i < nUvLayers; i++ ) {
149 
150 			geometry.faceUvs[ i ] = [];
151 			geometry.faceVertexUvs[ i ] = [];
152 
153 		}
154 
155 		offset = 0;
156 		zLength = vertices.length;
157 
158 		while ( offset < zLength ) {
159 
160 			vertex = new THREE.Vector3();
161 
162 			vertex.x = vertices[ offset ++ ] * scale;
163 			vertex.y = vertices[ offset ++ ] * scale;
164 			vertex.z = vertices[ offset ++ ] * scale;
165 
166 			geometry.vertices.push( vertex );
167 
168 		}
169 
170 		offset = 0;
171 		zLength = faces.length;
172 
173 		while ( offset < zLength ) {
174 
175 			type = faces[ offset ++ ];
176 
177 
178 			isQuad          	= isBitSet( type, 0 );
179 			hasMaterial         = isBitSet( type, 1 );
180 			hasFaceUv           = isBitSet( type, 2 );
181 			hasFaceVertexUv     = isBitSet( type, 3 );
182 			hasFaceNormal       = isBitSet( type, 4 );
183 			hasFaceVertexNormal = isBitSet( type, 5 );
184 			hasFaceColor	    = isBitSet( type, 6 );
185 			hasFaceVertexColor  = isBitSet( type, 7 );
186 
187 			//console.log("type", type, "bits", isQuad, hasMaterial, hasFaceUv, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
188 
189 			if ( isQuad ) {
190 
191 				face = new THREE.Face4();
192 
193 				face.a = faces[ offset ++ ];
194 				face.b = faces[ offset ++ ];
195 				face.c = faces[ offset ++ ];
196 				face.d = faces[ offset ++ ];
197 
198 				nVertices = 4;
199 
200 			} else {
201 
202 				face = new THREE.Face3();
203 
204 				face.a = faces[ offset ++ ];
205 				face.b = faces[ offset ++ ];
206 				face.c = faces[ offset ++ ];
207 
208 				nVertices = 3;
209 
210 			}
211 
212 			if ( hasMaterial ) {
213 
214 				materialIndex = faces[ offset ++ ];
215 				face.materialIndex = materialIndex;
216 
217 			}
218 
219 			// to get face <=> uv index correspondence
220 
221 			fi = geometry.faces.length;
222 
223 			if ( hasFaceUv ) {
224 
225 				for ( i = 0; i < nUvLayers; i++ ) {
226 
227 					uvLayer = json.uvs[ i ];
228 
229 					uvIndex = faces[ offset ++ ];
230 
231 					u = uvLayer[ uvIndex * 2 ];
232 					v = uvLayer[ uvIndex * 2 + 1 ];
233 
234 					geometry.faceUvs[ i ][ fi ] = new THREE.UV( u, v );
235 
236 				}
237 
238 			}
239 
240 			if ( hasFaceVertexUv ) {
241 
242 				for ( i = 0; i < nUvLayers; i++ ) {
243 
244 					uvLayer = json.uvs[ i ];
245 
246 					uvs = [];
247 
248 					for ( j = 0; j < nVertices; j ++ ) {
249 
250 						uvIndex = faces[ offset ++ ];
251 
252 						u = uvLayer[ uvIndex * 2 ];
253 						v = uvLayer[ uvIndex * 2 + 1 ];
254 
255 						uvs[ j ] = new THREE.UV( u, v );
256 
257 					}
258 
259 					geometry.faceVertexUvs[ i ][ fi ] = uvs;
260 
261 				}
262 
263 			}
264 
265 			if ( hasFaceNormal ) {
266 
267 				normalIndex = faces[ offset ++ ] * 3;
268 
269 				normal = new THREE.Vector3();
270 
271 				normal.x = normals[ normalIndex ++ ];
272 				normal.y = normals[ normalIndex ++ ];
273 				normal.z = normals[ normalIndex ];
274 
275 				face.normal = normal;
276 
277 			}
278 
279 			if ( hasFaceVertexNormal ) {
280 
281 				for ( i = 0; i < nVertices; i++ ) {
282 
283 					normalIndex = faces[ offset ++ ] * 3;
284 
285 					normal = new THREE.Vector3();
286 
287 					normal.x = normals[ normalIndex ++ ];
288 					normal.y = normals[ normalIndex ++ ];
289 					normal.z = normals[ normalIndex ];
290 
291 					face.vertexNormals.push( normal );
292 
293 				}
294 
295 			}
296 
297 
298 			if ( hasFaceColor ) {
299 
300 				colorIndex = faces[ offset ++ ];
301 
302 				color = new THREE.Color( colors[ colorIndex ] );
303 				face.color = color;
304 
305 			}
306 
307 
308 			if ( hasFaceVertexColor ) {
309 
310 				for ( i = 0; i < nVertices; i++ ) {
311 
312 					colorIndex = faces[ offset ++ ];
313 
314 					color = new THREE.Color( colors[ colorIndex ] );
315 					face.vertexColors.push( color );
316 
317 				}
318 
319 			}
320 
321 			geometry.faces.push( face );
322 
323 		}
324 
325 	};
326 
327 	function parseSkin() {
328 
329 		var i, l, x, y, z, w, a, b, c, d;
330 
331 		if ( json.skinWeights ) {
332 
333 			for ( i = 0, l = json.skinWeights.length; i < l; i += 2 ) {
334 
335 				x = json.skinWeights[ i     ];
336 				y = json.skinWeights[ i + 1 ];
337 				z = 0;
338 				w = 0;
339 
340 				geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
341 
342 			}
343 
344 		}
345 
346 		if ( json.skinIndices ) {
347 
348 			for ( i = 0, l = json.skinIndices.length; i < l; i += 2 ) {
349 
350 				a = json.skinIndices[ i     ];
351 				b = json.skinIndices[ i + 1 ];
352 				c = 0;
353 				d = 0;
354 
355 				geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
356 
357 			}
358 
359 		}
360 
361 		geometry.bones = json.bones;
362 		geometry.animation = json.animation;
363 
364 	};
365 
366 	function parseMorphing( scale ) {
367 
368 		if ( json.morphTargets !== undefined ) {
369 
370 			var i, l, v, vl, dstVertices, srcVertices;
371 
372 			for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
373 
374 				geometry.morphTargets[ i ] = {};
375 				geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
376 				geometry.morphTargets[ i ].vertices = [];
377 
378 				dstVertices = geometry.morphTargets[ i ].vertices;
379 				srcVertices = json.morphTargets [ i ].vertices;
380 
381 				for( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
382 
383 					var vertex = new THREE.Vector3();
384 					vertex.x = srcVertices[ v ] * scale;
385 					vertex.y = srcVertices[ v + 1 ] * scale;
386 					vertex.z = srcVertices[ v + 2 ] * scale;
387 
388 					dstVertices.push( vertex );
389 
390 				}
391 
392 			}
393 
394 		}
395 
396 		if ( json.morphColors !== undefined ) {
397 
398 			var i, l, c, cl, dstColors, srcColors, color;
399 
400 			for ( i = 0, l = json.morphColors.length; i < l; i++ ) {
401 
402 				geometry.morphColors[ i ] = {};
403 				geometry.morphColors[ i ].name = json.morphColors[ i ].name;
404 				geometry.morphColors[ i ].colors = [];
405 
406 				dstColors = geometry.morphColors[ i ].colors;
407 				srcColors = json.morphColors [ i ].colors;
408 
409 				for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
410 
411 					color = new THREE.Color( 0xffaa00 );
412 					color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
413 					dstColors.push( color );
414 
415 				}
416 
417 			}
418 
419 		}
420 
421 	};
422 
423 	var materials = this.initMaterials( json.materials, texturePath );
424 
425 	if ( this.needsTangents( materials ) ) geometry.computeTangents();
426 
427 	callback( geometry, materials );
428 
429 };
430 

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