Cleaning
This commit is contained in:
		
							parent
							
								
									638111c3b1
								
							
						
					
					
						commit
						5fca88ea8f
					
				| @ -1,194 +1,194 @@ | ||||
| var ProgressiveLoader = function(path, scene, materialCreator, transparentElements) { | ||||
|     if (transparentElements === undefined) { | ||||
|         transparentElements = []; | ||||
|     } | ||||
| var ProgressiveLoader = function(path, scene, callback) { | ||||
|     // Create MTLLoader
 | ||||
|     var loader = new THREE.MTLLoader(path.substring(0, path.lastIndexOf('/')) + '/'); | ||||
|     loader.load(path.replace('.obj', '.mtl'), function(materialCreator) { | ||||
| 
 | ||||
|     // Create mesh
 | ||||
|     var obj = new THREE.Object3D(); | ||||
|     obj.up = new THREE.Vector3(0,0,1); | ||||
|     glob = obj; | ||||
|         materialCreator.preload(); | ||||
| 
 | ||||
|     var currentMesh; | ||||
|     var currentMaterial; | ||||
|         // Create mesh
 | ||||
|         var obj = new THREE.Object3D(); | ||||
|         obj.up = new THREE.Vector3(0,0,1); | ||||
|         glob = obj; | ||||
| 
 | ||||
|     var added = false; | ||||
|     var finished = false; | ||||
|         var currentMesh; | ||||
|         var currentMaterial; | ||||
| 
 | ||||
|     var socket = io(); | ||||
|         var added = false; | ||||
|         var finished = false; | ||||
| 
 | ||||
|     var vertices = []; | ||||
|     var textCoords = []; | ||||
|     var uvs = []; | ||||
|     var faces = []; | ||||
|         var socket = io(); | ||||
| 
 | ||||
|     // Init streaming with socket
 | ||||
|     socket.emit('request', path); | ||||
|         var vertices = []; | ||||
|         var textCoords = []; | ||||
|         var uvs = []; | ||||
|         var faces = []; | ||||
| 
 | ||||
|     // When server's ready, start asking for the mesh
 | ||||
|     socket.on('ok', function() { | ||||
|         socket.emit('next'); | ||||
|     }); | ||||
|         // Init streaming with socket
 | ||||
|         socket.emit('request', path.substring(1, path.length)); | ||||
| 
 | ||||
|     // When receiving elements
 | ||||
|     socket.on('elements', function(arr) { | ||||
| 
 | ||||
|         console.log("Got stuff"); | ||||
| 
 | ||||
|         if (!finished) { | ||||
|         // When server's ready, start asking for the mesh
 | ||||
|         socket.on('ok', function() { | ||||
|             socket.emit('next'); | ||||
|         } | ||||
|         }); | ||||
| 
 | ||||
|         // Launch this code in async
 | ||||
|         setTimeout(function() { | ||||
|         // When receiving elements
 | ||||
|         socket.on('elements', function(arr) { | ||||
| 
 | ||||
|             // We'll receive an array of string (obj)
 | ||||
|             for (var i = 0; i < arr.length; i++) { | ||||
|             console.log("Got stuff"); | ||||
| 
 | ||||
|                 var elts = arr[i]; | ||||
|             if (!finished) { | ||||
|                 socket.emit('next'); | ||||
|             } | ||||
| 
 | ||||
|                 // console.log(line);
 | ||||
|             // Launch this code in async
 | ||||
|             setTimeout(function() { | ||||
| 
 | ||||
|                 if (elts[0] === 'v') { | ||||
|                 // We'll receive an array of string (obj)
 | ||||
|                 for (var i = 0; i < arr.length; i++) { | ||||
| 
 | ||||
|                     vertices.push(new THREE.Vector3( | ||||
|                         elts[1], | ||||
|                         elts[2], | ||||
|                         elts[3] | ||||
|                     )); | ||||
|                     var elts = arr[i]; | ||||
| 
 | ||||
|                 } else if (elts[0] === 'vt') { | ||||
|                     // console.log(line);
 | ||||
| 
 | ||||
|                     textCoords.push(new THREE.Vector2( | ||||
|                         elts[1], | ||||
|                         elts[2] | ||||
|                     )); | ||||
|                     if (elts[0] === 'v') { | ||||
| 
 | ||||
|                 } else if (elts[0] === 'f') { | ||||
|                         vertices.push(new THREE.Vector3( | ||||
|                             elts[1], | ||||
|                             elts[2], | ||||
|                             elts[3] | ||||
|                         )); | ||||
| 
 | ||||
|                     faces.push(new THREE.Face3( | ||||
|                         elts[1], | ||||
|                         elts[2], | ||||
|                         elts[3] | ||||
|                     )); | ||||
|                     } else if (elts[0] === 'vt') { | ||||
| 
 | ||||
|                     // If the face has 4 vertices, create second triangle
 | ||||
|                     if (elts.length === 5 || elts.length === 9) { | ||||
|                         textCoords.push(new THREE.Vector2( | ||||
|                             elts[1], | ||||
|                             elts[2] | ||||
|                         )); | ||||
| 
 | ||||
|                     } else if (elts[0] === 'f') { | ||||
| 
 | ||||
|                         faces.push(new THREE.Face3( | ||||
|                             elts[1], | ||||
|                             elts[3], | ||||
|                             elts[4] | ||||
|                             elts[2], | ||||
|                             elts[3] | ||||
|                         )); | ||||
| 
 | ||||
|                     } | ||||
|                         // If the face has 4 vertices, create second triangle
 | ||||
|                         if (elts.length === 5 || elts.length === 9) { | ||||
| 
 | ||||
|                     // Add texture
 | ||||
|                     if (elts.length === 7) { | ||||
|                         uvs.push([ | ||||
|                             textCoords[elts[4]], | ||||
|                             textCoords[elts[5]], | ||||
|                             textCoords[elts[6]] | ||||
|                         ]); | ||||
|                     } | ||||
|                             faces.push(new THREE.Face3( | ||||
|                                 elts[1], | ||||
|                                 elts[3], | ||||
|                                 elts[4] | ||||
|                             )); | ||||
| 
 | ||||
|                     if (elts.length === 9) { | ||||
|                         uvs.push([ | ||||
|                             textCoords[elts[5]], | ||||
|                             textCoords[elts[6]], | ||||
|                             textCoords[elts[7]] | ||||
|                         ]); | ||||
|                     } | ||||
| 
 | ||||
|                     if (elts.length === 9) { | ||||
|                         uvs.push([ | ||||
|                             textCoords[elts[5]], | ||||
|                             textCoords[elts[7]], | ||||
|                             textCoords[elts[8]] | ||||
|                         ]); | ||||
|                     } | ||||
| 
 | ||||
|                     // Add currentMesh to scene one there are a few faces in it
 | ||||
|                     if (!added) { | ||||
|                         scene.add(obj); | ||||
|                         added = true; | ||||
|                     } | ||||
| 
 | ||||
|                     if (!currentMesh) { | ||||
|                         var geo = new THREE.Geometry(); | ||||
|                         geo.vertices = vertices; | ||||
|                         geo.faces = faces; | ||||
|                         geo.faceVertexUvs = [uvs]; | ||||
| 
 | ||||
| 
 | ||||
|                         var material, tmp = currentMaterial; | ||||
|                         if (currentMaterial === undefined || currentMaterial === null) { | ||||
|                             material = new THREE.MeshLambertMaterial({color: 'red'}); | ||||
|                         } else { | ||||
|                             material = materialCreator.materials[currentMaterial.trim()]; | ||||
|                             material.side = THREE.DoubleSide; | ||||
|                             if (material.map) | ||||
|                                 material.map.wrapS = material.map.wrapT = THREE.RepeatWrapping; | ||||
| 
 | ||||
|                             currentMaterial = null; | ||||
|                         } | ||||
|                         currentMesh = new THREE.Mesh(geo, material); | ||||
| 
 | ||||
|                         if (tmp && transparentElements.indexOf(tmp.trim()) !== -1) { | ||||
|                             THREEx.Transparency.push(currentMesh); | ||||
|                         } else { | ||||
|                             currentMesh.raycastable = true; | ||||
|                         } | ||||
| 
 | ||||
|                         currentMesh.geometry.computeFaceNormals(); | ||||
|                         // Add texture
 | ||||
|                         if (elts.length === 7) { | ||||
|                             uvs.push([ | ||||
|                                 textCoords[elts[4]], | ||||
|                                 textCoords[elts[5]], | ||||
|                                 textCoords[elts[6]] | ||||
|                             ]); | ||||
|                         } | ||||
| 
 | ||||
|                         if (elts.length === 9) { | ||||
|                             uvs.push([ | ||||
|                                 textCoords[elts[5]], | ||||
|                                 textCoords[elts[6]], | ||||
|                                 textCoords[elts[7]] | ||||
|                             ]); | ||||
|                         } | ||||
| 
 | ||||
|                         if (elts.length === 9) { | ||||
|                             uvs.push([ | ||||
|                                 textCoords[elts[5]], | ||||
|                                 textCoords[elts[7]], | ||||
|                                 textCoords[elts[8]] | ||||
|                             ]); | ||||
|                         } | ||||
| 
 | ||||
|                         // Add currentMesh to scene one there are a few faces in it
 | ||||
|                         if (!added) { | ||||
|                             scene.add(obj); | ||||
|                             added = true; | ||||
|                         } | ||||
| 
 | ||||
|                         if (!currentMesh) { | ||||
|                             var geo = new THREE.Geometry(); | ||||
|                             geo.vertices = vertices; | ||||
|                             geo.faces = faces; | ||||
|                             geo.faceVertexUvs = [uvs]; | ||||
| 
 | ||||
| 
 | ||||
|                             var material, tmp = currentMaterial; | ||||
|                             if (currentMaterial === undefined || currentMaterial === null) { | ||||
|                                 material = new THREE.MeshLambertMaterial({color: 'red'}); | ||||
|                             } else { | ||||
|                                 material = materialCreator.materials[currentMaterial.trim()]; | ||||
|                                 material.side = THREE.DoubleSide; | ||||
|                                 if (material.map) | ||||
|                                     material.map.wrapS = material.map.wrapT = THREE.RepeatWrapping; | ||||
| 
 | ||||
|                                 currentMaterial = null; | ||||
|                             } | ||||
|                             currentMesh = new THREE.Mesh(geo, material); | ||||
| 
 | ||||
|                             if (typeof callback === 'function') { | ||||
|                                 callback(currentMesh, obj); | ||||
|                             } | ||||
| 
 | ||||
|                             currentMesh.geometry.computeFaceNormals(); | ||||
|                         } | ||||
|                         obj.add(currentMesh); | ||||
| 
 | ||||
|                     } else if (elts[0] === 'u') { | ||||
| 
 | ||||
|                         // Add current mesh
 | ||||
|                         // if (currentMesh) {
 | ||||
|                         //     obj.add(currentMesh);
 | ||||
|                         // }
 | ||||
| 
 | ||||
|                         // Prepare new mesh
 | ||||
|                         faces = []; | ||||
|                         uvs = []; | ||||
|                         // currentMesh.geometry.computeFaceNormals();
 | ||||
|                         if (currentMesh) { | ||||
|                             currentMesh.geometry.computeFaceNormals(); | ||||
|                             currentMesh.geometry.computeBoundingSphere(); | ||||
|                             currentMesh.geometry.groupsNeedUpdate = true; | ||||
|                             currentMesh.geometry.elementsNeedUpdate = true; | ||||
|                             currentMesh.geometry.normalsNeedUpdate = true; | ||||
|                             currentMesh.geometry.uvsNeedUpdate = true; | ||||
|                         } | ||||
|                         currentMaterial = elts[1]; | ||||
|                         currentMesh = null; | ||||
| 
 | ||||
|                         // console.log(material.map);
 | ||||
|                         // currentMesh = new THREE.Mesh(geo, material);
 | ||||
| 
 | ||||
|                     } | ||||
|                     obj.add(currentMesh); | ||||
| 
 | ||||
|                 } else if (elts[0] === 'u') { | ||||
| 
 | ||||
|                     // Add current mesh
 | ||||
|                     // if (currentMesh) {
 | ||||
|                     //     obj.add(currentMesh);
 | ||||
|                     // }
 | ||||
| 
 | ||||
|                     // Prepare new mesh
 | ||||
|                     faces = []; | ||||
|                     uvs = []; | ||||
|                     // currentMesh.geometry.computeFaceNormals();
 | ||||
|                     if (currentMesh) { | ||||
|                         currentMesh.geometry.computeFaceNormals(); | ||||
|                         currentMesh.geometry.computeBoundingSphere(); | ||||
|                         currentMesh.geometry.groupsNeedUpdate = true; | ||||
|                         currentMesh.geometry.elementsNeedUpdate = true; | ||||
|                         currentMesh.geometry.normalsNeedUpdate = true; | ||||
|                         currentMesh.geometry.uvsNeedUpdate = true; | ||||
|                     } | ||||
|                     currentMaterial = elts[1]; | ||||
|                     currentMesh = null; | ||||
| 
 | ||||
|                     // console.log(material.map);
 | ||||
|                     // currentMesh = new THREE.Mesh(geo, material);
 | ||||
| 
 | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|                 if (currentMesh) { | ||||
|                     currentMesh.material.side = THREE.DoubleSide; | ||||
|                     currentMesh.geometry.computeFaceNormals(); | ||||
|                     currentMesh.geometry.computeBoundingSphere(); | ||||
|                     currentMesh.geometry.groupsNeedUpdate = true; | ||||
|                     currentMesh.geometry.elementsNeedUpdate = true; | ||||
|                     currentMesh.geometry.normalsNeedUpdate = true; | ||||
|                     currentMesh.geometry.uvsNeedUpdate = true; | ||||
|                 } | ||||
| 
 | ||||
|             if (currentMesh) { | ||||
|                 currentMesh.material.side = THREE.DoubleSide; | ||||
|                 currentMesh.geometry.computeFaceNormals(); | ||||
|                 currentMesh.geometry.computeBoundingSphere(); | ||||
|                 currentMesh.geometry.groupsNeedUpdate = true; | ||||
|                 currentMesh.geometry.elementsNeedUpdate = true; | ||||
|                 currentMesh.geometry.normalsNeedUpdate = true; | ||||
|                 currentMesh.geometry.uvsNeedUpdate = true; | ||||
|             } | ||||
|             },0); | ||||
|         }); | ||||
| 
 | ||||
|         socket.on('disconnect', function() { | ||||
|             console.log("Finished"); | ||||
|             finished = true; | ||||
|         }); | ||||
| 
 | ||||
|         },0); | ||||
|     }); | ||||
| 
 | ||||
|     socket.on('disconnect', function() { | ||||
|         console.log("Finished"); | ||||
|         finished = true; | ||||
|     }); | ||||
| 
 | ||||
|     return obj; | ||||
| } | ||||
|  | ||||
							
								
								
									
										382
									
								
								js/prototype/initScene.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										382
									
								
								js/prototype/initScene.js
									
									
									
									
										vendored
									
									
								
							| @ -12,84 +12,25 @@ function addLight(scene) { | ||||
| } | ||||
| 
 | ||||
| function initPeachCastle(scene, collidableObjects, loader, static_path) { | ||||
|     // Create loader if not already done
 | ||||
|     if (loader === undefined) { | ||||
|         loader = new THREE.OBJMTLLoader(); | ||||
|     } | ||||
| 
 | ||||
|     // Try to guess the path to static files
 | ||||
|     if (static_path === undefined) { | ||||
|         static_path = "/static/"; | ||||
|     } | ||||
| 
 | ||||
|     // var loader = new THREE.MTLLoader('/static/data/castle/');
 | ||||
|     // loader.load('/static/data/castle/princess peaches castle (outside).mtl', function(materialCreator) {
 | ||||
| 
 | ||||
|     //     materialCreator.preload();
 | ||||
| 
 | ||||
|     //     var mesh = ProgressiveLoader('static/data/castle/princess peaches castle (outside).obj', scene, materialCreator);
 | ||||
|     // });
 | ||||
| 
 | ||||
|     loader.load( | ||||
|         static_path + 'data/castle/princess peaches castle (outside).obj', | ||||
|         static_path + 'data/castle/princess peaches castle (outside).mtl', | ||||
|         function ( object ) { | ||||
|             glob = object; | ||||
|             object.up = new THREE.Vector3(0,0,1); | ||||
|             scene.add(object); | ||||
|     ProgressiveLoader( | ||||
|         '/static/data/castle/princess peaches castle (outside).obj', | ||||
|         scene, | ||||
|         function(object, container) { | ||||
|             collidableObjects.push(object); | ||||
|             object.traverse(function (object) { | ||||
|                 if (object instanceof THREE.Mesh) { | ||||
|                     object.geometry.mergeVertices(); | ||||
|                     object.geometry.computeVertexNormals(); | ||||
|                     object.material.side = THREE.DoubleSide; | ||||
|                     object.raycastable = true; | ||||
|                     if (object.material.name === 'Material.103_princess_peaches_cast') { | ||||
|                         THREEx.Transparency.push(object); | ||||
|                     } else if (object.material.name === 'Material.136_princess_peaches_cast' || | ||||
|                         object.material.name === 'Material.135_princess_peaches_cast') { | ||||
|                         THREEx.Transparency.push(object); | ||||
|                         object.material.opacity = 0.5; | ||||
|                         object.material.side = THREE.FrontSide; | ||||
|                         object.raycastable = false; | ||||
|                         var newObj = object.clone(); | ||||
|                         newObj.material = object.material.clone(); | ||||
|                         newObj.material.side = THREE.BackSide; | ||||
|                         scene.add(newObj); | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|             object.raycastable = true; | ||||
|             if (object.material.name === 'Material.103_princess_peaches_cast') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|             } else if (object.material.name === 'Material.136_princess_peaches_cast' || | ||||
|                        object.material.name === 'Material.135_princess_peaches_cast') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|                 object.material.opacity = 0.5; | ||||
|                 object.raycastable = false; | ||||
|                 object.material.side = THREE.FrontSide; | ||||
|             } | ||||
|         } | ||||
|     ); | ||||
| 
 | ||||
|     // loader.load(
 | ||||
|     //     static_path + 'data/first/Floor 1.obj',
 | ||||
|     //     static_path + 'data/first/Floor 1.mtl',
 | ||||
|     //     function ( object ) {
 | ||||
|     //         object.position.z -= 10.9;
 | ||||
|     //         object.position.y += 0.555;
 | ||||
|     //         object.position.x += 3.23;
 | ||||
| 
 | ||||
|     //         var theta = 0.27;
 | ||||
|     //         object.rotation.y = Math.PI - theta;
 | ||||
| 
 | ||||
|     //         object.up = new THREE.Vector3(0,0,1);
 | ||||
|     //         scene.add(object);
 | ||||
|     //         collidableObjects.push(object);
 | ||||
|     //         object.traverse(function (object) {
 | ||||
|     //             if (object instanceof THREE.Mesh) {
 | ||||
|     //                 object.material.side = THREE.DoubleSide;
 | ||||
|     //                 object.geometry.mergeVertices();
 | ||||
|     //                 object.geometry.computeVertexNormals();
 | ||||
|     //                 object.raycastable = true;
 | ||||
|     //                 if (object.material.name === 'Material.054_777F0E0B_c.bmp' ||
 | ||||
|     //                     object.material.name === 'Material.061_5C3492AB_c.bmp'   ) {
 | ||||
|     //                     THREEx.Transparency.push(object);
 | ||||
|     //                 }
 | ||||
|     //             }
 | ||||
|     //         });
 | ||||
|     //     }
 | ||||
|     // );
 | ||||
| } | ||||
| 
 | ||||
| function resetPeachElements() { | ||||
| @ -154,39 +95,6 @@ function initZeldaScene(scene, collidableObjects, loader, static_path) { | ||||
|         } | ||||
|     ); | ||||
| 
 | ||||
|     // loader.load(
 | ||||
|     //     static_path + 'data/zelda/Sea.obj',
 | ||||
|     //     static_path + 'data/zelda/Sea.mtl',
 | ||||
|     //     function ( object ) {
 | ||||
|     //         scene.add(object);
 | ||||
|     //         collidableObjects.push(object);
 | ||||
|     //         object.scale.set(0.01,0.01,0.01);
 | ||||
|     //         object.traverse(function (object) {
 | ||||
|     //             if (object instanceof THREE.Mesh) {
 | ||||
|     //                 object.geometry.mergeVertices();
 | ||||
|     //                 object.geometry.computeVertexNormals();
 | ||||
|     //                 object.raycastable = true;
 | ||||
|     //             }
 | ||||
|     //         });
 | ||||
|     //     }
 | ||||
|     // );
 | ||||
| 
 | ||||
|     // loader.load(
 | ||||
|     //     static_path + 'data/zelda/Window Lights.obj',
 | ||||
|     //     static_path + 'data/zelda/Window Lights.mtl',
 | ||||
|     //     function ( object ) {
 | ||||
|     //         scene.add(object);
 | ||||
|     //         collidableObjects.push(object);
 | ||||
|     //         object.scale.set(0.01,0.01,0.01);
 | ||||
|     //         object.traverse(function (object) {
 | ||||
|     //             if (object instanceof THREE.Mesh) {
 | ||||
|     //                 object.geometry.mergeVertices();
 | ||||
|     //                 object.geometry.computeVertexNormals();
 | ||||
|     //                 object.raycastable = true;
 | ||||
|     //             }
 | ||||
|     //         });
 | ||||
|     //     }
 | ||||
|     // );
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -217,7 +125,8 @@ function createPeachCameras(width, height) { | ||||
|     cams.push(createCamera( | ||||
|             new THREE.Vector3(2.625389073616235, 1.2252620948239699, -4.818718135555419), | ||||
|             new THREE.Vector3(-19.756833131355208, -16.20027570329664, -33.02132017177813) | ||||
|     )); | ||||
|     ));ader = new THREE.MTLLoader('/static/data/bobomb/'); | ||||
|     // loader.
 | ||||
| 
 | ||||
|     // cams.push(createCamera(
 | ||||
|     //         new THREE.Vector3(1.3304975149911331, 0.4836093721106701, -8.60618907952783),
 | ||||
| @ -251,99 +160,23 @@ function createPeachCameras(width, height) { | ||||
| 
 | ||||
| function initBobombScene(scene, collidableObjects, loader, static_path) { | ||||
| 
 | ||||
|     // var loader = new THREE.MTLLoader('/static/data/bobomb/');
 | ||||
|     // loader.load('/static/data/bobomb/bobomb battlefeild.mtl', function(materialCreator) {
 | ||||
| 
 | ||||
|     //     materialCreator.preload();
 | ||||
|     //     var mesh = ProgressiveLoader('static/data/bobomb/bobomb battlefeild.obj', scene, materialCreator, [
 | ||||
|     //         'Material.071_574B138E_c.bmp',
 | ||||
|     //         'Material.070_41A41EE3_c.bmp'
 | ||||
|     //     ]);
 | ||||
| 
 | ||||
|     //     // object.position.z -= 10.9;
 | ||||
|     //     // object.position.y += 0.555;
 | ||||
|     //     // object.position.x += 3.23;
 | ||||
| 
 | ||||
|     //     var theta = 0.27;
 | ||||
|     //     mesh.rotation.y = Math.PI - theta;
 | ||||
|     //     mesh.up = new THREE.Vector3(0,0,1);
 | ||||
|     //     collidableObjects.push(mesh);
 | ||||
|     // });
 | ||||
| 
 | ||||
| 
 | ||||
|     // Create loader if not already done
 | ||||
|     if (loader === undefined) { | ||||
|         loader = new THREE.OBJMTLLoader(); | ||||
|     } | ||||
| 
 | ||||
|     // Try to guess the path to static files
 | ||||
|     if (static_path === undefined) { | ||||
|         static_path = "/static/"; | ||||
|     } | ||||
| 
 | ||||
|     loader.load( | ||||
|     ProgressiveLoader( | ||||
|         static_path + 'data/bobomb/bobomb battlefeild.obj', | ||||
|         static_path + 'data/bobomb/bobomb battlefeild.mtl', | ||||
|         function ( object ) { | ||||
|             // object.position.z -= 10.9;
 | ||||
|             // object.position.y += 0.555;
 | ||||
|             // object.position.x += 3.23;
 | ||||
| 
 | ||||
|         scene, | ||||
|         function(object) { | ||||
|             var theta = 0.27; | ||||
|             object.rotation.y = Math.PI - theta; | ||||
| 
 | ||||
|             object.up = new THREE.Vector3(0,0,1); | ||||
|             collidableObjects.push(object); | ||||
|             scene.add(object); | ||||
|             glob = object; | ||||
|             object.traverse(function (object) { | ||||
|                 if (object instanceof THREE.Mesh) { | ||||
|                     object.raycastable = true; | ||||
|                     object.material.side = THREE.DoubleSide; | ||||
|                     object.geometry.mergeVertices(); | ||||
|                     object.geometry.computeVertexNormals(); | ||||
|                     if (object.material.name === 'Material.071_574B138E_c.bmp' || | ||||
|                         object.material.name === 'Material.070_41A41EE3_c.bmp') { | ||||
|                         THREEx.Transparency.push(object); | ||||
|                     } | ||||
| 
 | ||||
|                 } | ||||
|             }); | ||||
|             object.raycastable = true; | ||||
|             if (object.material.name === 'Material.071_574B138E_c.bmp' || | ||||
|                 object.material.name === 'Material.070_41A41EE3_c.bmp') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|             } | ||||
|         } | ||||
|     ); | ||||
| 
 | ||||
|     // loader.load(
 | ||||
|     //     static_path + 'data/star/GrandStar.obj',
 | ||||
|     //     static_path + 'data/star/GrandStar.mtl',
 | ||||
|     //     function ( object ) {
 | ||||
|     //         object.position.z -= 10.9;
 | ||||
|     //         object.position.y += 0.555;
 | ||||
|     //         object.position.x += 3.23;
 | ||||
| 
 | ||||
|     //         var theta = 0.27;
 | ||||
|     //         object.rotation.y = Math.PI - theta;
 | ||||
| 
 | ||||
|     //         object.up = new THREE.Vector3(0,0,1);
 | ||||
|     //         scene.add(object);
 | ||||
|     //         collidableObjects.push(object);
 | ||||
|     //         object.traverse(function (object) {
 | ||||
|     //             if (object instanceof THREE.Mesh) {
 | ||||
|     //                 object.scale.set(0.005,0.005,0.005);
 | ||||
|     //                 object.position.x = 13;
 | ||||
|     //                 object.position.z = -35;
 | ||||
|     //                 object.position.y = 30;
 | ||||
| 
 | ||||
|     //                 object.rotation.z = Math.PI/2;
 | ||||
|     //                 object.rotation.x = Math.PI/2;
 | ||||
|     //                 object.rotation.y = Math.PI;
 | ||||
|     //                 object.material.side = THREE.DoubleSide;
 | ||||
|     //                 object.geometry.mergeVertices();
 | ||||
|     //                 object.geometry.computeVertexNormals();
 | ||||
|     //                 object.raycastable = true;
 | ||||
|     //             }
 | ||||
|     //         });
 | ||||
|     //     }
 | ||||
|     //);
 | ||||
| } | ||||
| 
 | ||||
| function resetBobombElements() { | ||||
| @ -469,36 +302,29 @@ function initBobomb(camera, scene, static_path, coins) { | ||||
| } | ||||
| 
 | ||||
| function initWhompScene(scene, collidableObjects, loader, static_path) { | ||||
|     loader.load( | ||||
|         static_path + './data/whomp/Whomps Fortress.obj', | ||||
|         static_path + './data/whomp/Whomps Fortress.mtl', | ||||
|         function ( object ) { | ||||
| 
 | ||||
|     ProgressiveLoader( | ||||
|         static_path + 'data/whomp/Whomps Fortress.obj', | ||||
|         scene, | ||||
|         function(object) { | ||||
|             object.rotation.x = -Math.PI/2; | ||||
|             object.rotation.z = Math.PI/2; | ||||
|             object.scale.set(0.1,0.1,0.1); | ||||
|             collidableObjects.push(object); | ||||
|             scene.add(object); | ||||
|             object.traverse(function (obj) { | ||||
|                 if (obj instanceof THREE.Mesh) { | ||||
|                     obj.geometry.mergeVertices(); | ||||
|                     obj.geometry.computeVertexNormals(); | ||||
|                     obj.material.side = THREE.DoubleSide; | ||||
|                     obj.raycastable = true; | ||||
|             object.raycastable = true; | ||||
|             if (object.material.name === 'Shape_088' || | ||||
|                 object.material.name === 'Shape_089') { | ||||
|                 object.raycastable = false; | ||||
|             THREEx.Transparency.push(object); | ||||
|             } else if (object.material.name === 'Shape_113') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|                 object.material.opacity = 0.5; | ||||
|             } else if (object.material.name === 'Shape_076' || | ||||
|                        object.material.name === 'Shape_098' || | ||||
|                        object.material.name === 'Shape_092') { | ||||
|                 object.visible = false; | ||||
|             } | ||||
| 
 | ||||
|                     if (obj.material.name === 'Shape_088' || | ||||
|                         obj.material.name === 'Shape_089') { | ||||
|                         obj.raycastable = false; | ||||
|                         THREEx.Transparency.push(obj); | ||||
|                     } else if (obj.material.name === 'Shape_113') { | ||||
|                         THREEx.Transparency.push(obj); | ||||
|                         obj.material.opacity = 0.5; | ||||
|                     } else if (obj.material.name === 'Shape_076' || | ||||
|                                obj.material.name === 'Shape_098' || | ||||
|                                obj.material.name === 'Shape_092') { | ||||
|                         obj.visible = false; | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     ); | ||||
| } | ||||
| @ -623,39 +449,31 @@ function initWhomp(camera, scene, static_path, coins) { | ||||
| } | ||||
| 
 | ||||
| function initMountainScene(scene, collidableObjects, loader, static_path) { | ||||
|     loader.load( | ||||
|         static_path + './data/mountain/coocoolmountain.obj', | ||||
|         static_path + './data/mountain/coocoolmountain.mtl', | ||||
|         // static_path + './data/mountain2/untitled.obj',
 | ||||
|         // static_path + './data/mountain2/untitled.mtl',
 | ||||
|         function ( object ) { | ||||
| 
 | ||||
|     ProgressiveLoader( | ||||
|         static_path + 'data/mountain/coocoolmountain.obj', | ||||
|         scene, | ||||
|         function(object) { | ||||
|             // object.rotation.x = -Math.PI/2;
 | ||||
|             // object.rotation.z = Math.PI/2;
 | ||||
|             collidableObjects.push(object); | ||||
|             scene.add(object); | ||||
|             object.traverse(function (obj) { | ||||
|                 if (obj instanceof THREE.Mesh) { | ||||
|                     obj.geometry.mergeVertices(); | ||||
|                     obj.geometry.computeVertexNormals(); | ||||
|                     obj.material.side = THREE.DoubleSide; | ||||
|                     obj.raycastable = true; | ||||
|                     if (obj.material.name === 'Material.070_13F025D5_c2.png' || | ||||
|                         obj.material.name === 'Material.068_5972FC88_c.bmp' || | ||||
|                         obj.material.name === 'Material.073_76F611AD_c.bmp' || | ||||
|                         obj.material.name === 'Material.071_76F611AD_c.bmp' || | ||||
|                         obj.material.name === 'Material.072_1723CCC7_c.bmp' || | ||||
|                         obj.material.name === 'Material.069_78B64DC7_c.bmp' || | ||||
|                         obj.material.name === 'Material.070_13F025D5_c.bmp' || | ||||
|                         obj.material.name === 'Material.078_3165B23A_c.bmp' || | ||||
|                         obj.material.name === 'Material.067_1723CCC7_c.bmp' || | ||||
|                         obj.material.name === 'Material.066_36DB292F_c.bmp') { | ||||
|                         THREEx.Transparency.push(obj); | ||||
|                     } else if (obj.material.name === 'Material.082_6DAF90F6_c.bmp') { | ||||
|                         THREEx.Transparency.push(obj); | ||||
|                         obj.material.opacity = 0.5; | ||||
|                     } | ||||
|                 } | ||||
|             }); | ||||
|             object.raycastable = true; | ||||
|             if (object.material.name === 'Material.070_13F025D5_c2.png' || | ||||
|                 object.material.name === 'Material.068_5972FC88_c.bmp' || | ||||
|                 object.material.name === 'Material.073_76F611AD_c.bmp' || | ||||
|                 object.material.name === 'Material.071_76F611AD_c.bmp' || | ||||
|                 object.material.name === 'Material.072_1723CCC7_c.bmp' || | ||||
|                 object.material.name === 'Material.069_78B64DC7_c.bmp' || | ||||
|                 object.material.name === 'Material.070_13F025D5_c.bmp' || | ||||
|                 object.material.name === 'Material.078_3165B23A_c.bmp' || | ||||
|                 object.material.name === 'Material.067_1723CCC7_c.bmp' || | ||||
|                 object.material.name === 'Material.066_36DB292F_c.bmp') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|             } else if (object.material.name === 'Material.082_6DAF90F6_c.bmp') { | ||||
|                 THREEx.Transparency.push(object); | ||||
|                 object.material.opacity = 0.5; | ||||
|             } | ||||
|         } | ||||
|     ); | ||||
| } | ||||
| @ -782,66 +600,22 @@ function initMountain(camera, scene, static_path, coins) { | ||||
| 
 | ||||
| function initSponzaScene(scene, collidableObjects, loader, static_path) { | ||||
| 
 | ||||
|     var loader = new THREE.MTLLoader('/static/data/sponza/'); | ||||
|     loader.load('/static/data/sponza/sponza.mtl', function(materialCreator) { | ||||
|     ProgressiveLoader('/static/data/sponza/sponza.obj', scene, | ||||
|         function(obj) { | ||||
|             obj.scale.set(0.1,0.1,0.1); | ||||
|             collidableObjects.push(obj); | ||||
|             obj.raycastable = true; | ||||
| 
 | ||||
|         materialCreator.preload(); | ||||
|             if (obj.material.name === 'chain' || | ||||
|                 obj.material.name === 'leaf'  || | ||||
|                 obj.material.name === 'Material__57') { | ||||
| 
 | ||||
|         console.log("Starting loading..."); | ||||
|         var mesh = ProgressiveLoader('static/data/sponza/sponza.obj', scene, materialCreator, [ | ||||
|             'chain', | ||||
|             'leaf', | ||||
|             'Material__57' | ||||
|         ]); | ||||
|                 THREEx.Transparency.push(obj); | ||||
|             } | ||||
| 
 | ||||
|         // object.position.z -= 10.9;
 | ||||
|         // object.position.y += 0.555;
 | ||||
|         // object.position.x += 3.23;
 | ||||
|         mesh.scale.set(0.01,0.01,0.01); | ||||
|         mesh.raycastable = true; | ||||
|         collidableObjects.push(mesh); | ||||
|     }); | ||||
|         } | ||||
|     ); | ||||
| 
 | ||||
| 
 | ||||
|     // var onProgress = function ( xhr ) {
 | ||||
|     //     if ( xhr.lengthComputable ) {
 | ||||
|     //         var percentComplete = xhr.loaded / xhr.total * 100;
 | ||||
|     //         console.log( Math.round(percentComplete, 2) + '% downloaded' );
 | ||||
|     //     }
 | ||||
|     // };
 | ||||
| 
 | ||||
|     // loader.load(
 | ||||
|     //     static_path + './data/sponza/sponza.json',
 | ||||
|     //     function (geometry, materials) {
 | ||||
|     //         console.log("OK");
 | ||||
|     //         geometry.mergeVertices();
 | ||||
|     //         var material = new THREE.MeshFaceMaterial(materials);
 | ||||
|     //         var object = new THREE.Mesh(geometry, material);
 | ||||
|     //         object.scale.set(0.01,0.01,0.01);
 | ||||
|     //         object.raycastable = true;
 | ||||
|     //         collidableObjects.push(object);
 | ||||
|     //         // object.rotation.x = -Math.PI/2;
 | ||||
|     //         // object.rotation.z = Math.PI/2;
 | ||||
|     //         // collidableObjects.push(object);
 | ||||
|     //         // scene.add(object);
 | ||||
|     //         object.traverse(function (obj) {
 | ||||
|     //             if (obj instanceof THREE.Mesh) {
 | ||||
|     //                 for (var i in obj.material.materials) {
 | ||||
|     //                     var m = obj.material.materials[i].map;
 | ||||
|     //                     if (m)
 | ||||
|     //                         m.wrapS = m.wrapT = THREE.RepeatWrapping;
 | ||||
|     //                 }
 | ||||
|     //                 // obj.material.map.wrapS = obj.material.map.wrapT = THREE.RepeatWrapping;
 | ||||
|     //             }
 | ||||
|     //         //         obj.geometry.mergeVertices();
 | ||||
|     //         //         obj.geometry.computeVertexNormals();
 | ||||
|     //         //         obj.material.side = THREE.DoubleSide;
 | ||||
|     //         //         obj.raycastable = true;
 | ||||
|     //         //     }
 | ||||
|     //         });
 | ||||
|     //         scene.add(object);
 | ||||
|     //     }
 | ||||
|     // , onProgress, function(xhr) { console.log("error");});
 | ||||
| } | ||||
| 
 | ||||
| function createSponzaCoins() { | ||||
| @ -854,8 +628,8 @@ function createSponzaCameras() { | ||||
| 
 | ||||
| function resetSponzaElements() { | ||||
|     return { | ||||
|         position : new THREE.Vector3(-9.672189882510748,5.415297558602296,-1.5456794717808657), | ||||
|         target : new THREE.Vector3(27.18799151966882,-5.736834637451716,9.26898531637373) | ||||
|         position: new THREE.Vector3(92.98373669520107,60.8877777990862,11.130138641670737), | ||||
|         target: new THREE.Vector3(53.76696417668598,56.09739213575453,4.877382575136091) | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| @ -870,7 +644,7 @@ function initSponza(camera, scene, static_path, coins) { | ||||
|     camera.resetElements = resetSponzaElements(); | ||||
|     camera.collidableObjects = collidableObjects; | ||||
| 
 | ||||
|     camera.speed = 0.005; | ||||
|     camera.speed = 0.05; | ||||
|     camera.reset(); | ||||
|     camera.save(); | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										7
									
								
								js/prototype/main.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								js/prototype/main.js
									
									
									
									
										vendored
									
									
								
							| @ -79,9 +79,9 @@ function init() { | ||||
|     // Initialize pointer camera
 | ||||
|     var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.1, 100000, renderer, container); | ||||
| 
 | ||||
|     // cameras = initMainScene(camera1, scene, static_path, coins);
 | ||||
|     cameras = initMainScene(camera1, scene, static_path, coins); | ||||
|     // cameras = initPeach(camera1, scene, static_path, coins);
 | ||||
|     cameras = initBobomb(camera1, scene, static_path, coins); | ||||
|     // cameras = initBobomb(camera1, scene, static_path, coins);
 | ||||
|     // cameras = initWhomp(camera1, scene, static_path, coins);
 | ||||
|     // cameras = initMountain(camera1, scene, static_path, coins);
 | ||||
|     // cameras = initSponza(camera1, scene, static_path, coins);
 | ||||
| @ -158,6 +158,9 @@ function render() { | ||||
|     // Hide arrows in recommendation
 | ||||
|     cameras.map(function(camera) { if (camera instanceof RecommendedCamera) hide(camera); }); | ||||
| 
 | ||||
|     // Update transparent elements
 | ||||
|     THREEx.Transparency.update(cameras.mainCamera()); | ||||
| 
 | ||||
|     // Render preview
 | ||||
|     previewer.render(cameraSelecter.prev, container_size.width(), container_size.height()); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user