diff --git a/js/ProgressiveLoader.js b/js/ProgressiveLoader.js index db046df..a0fa8b0 100644 --- a/js/ProgressiveLoader.js +++ b/js/ProgressiveLoader.js @@ -26,6 +26,10 @@ var ProgressiveLoader = function(res, scene) { // When receiving elements socket.on('elements', function(arr) { + if (!finished) { + socket.emit('next'); + } + // Launch this code in async setTimeout(function() { @@ -78,34 +82,19 @@ var ProgressiveLoader = function(res, scene) { } + mesh.geometry.computeFaceNormals(); mesh.geometry.groupsNeedUpdate = true; mesh.geometry.elementsNeedUpdate = true; mesh.geometry.normalsNeedUpdate = true; - if (!finished) { - socket.emit('next'); - } else { - console.log("Finished"); - } },0); }); - socket.on('finished', function(arg) { + socket.on('disconnect', function() { + console.log("Finished"); finished = true; - mesh.faceNumber = arg; - //mesh.geometry.computeFaceNormals(); - mesh.geometry.verticesNeedUpdate = true; - mesh.geometry.groupsNeedUpdate = true; - mesh.geometry.elementsNeedUpdate = true; - mesh.geometry.morphTargetsNeedUpdate = true; - mesh.geometry.uvsNeedUpdate = true; - mesh.geometry.normalsNeedUpdate = true; - mesh.geometry.colorsNeedUpdate = true; - mesh.geometry.tangentsNeedUpdate = true; - - // scene.add(mesh); }); return mesh; diff --git a/socket.js b/socket.js index d432bfe..9be8776 100644 --- a/socket.js +++ b/socket.js @@ -39,9 +39,9 @@ module.exports = function(io) { // console.log(socket.conn.remoteAddress + " connected !"); - // socket.on('disconnect', function() { - // console.log(socket.conn.remoteAddress + " disconnected !"); - // }); + socket.on('disconnect', function() { + console.log(socket.conn.remoteAddress + " disconnected !"); + }); socket.on("request", function(res) { // console.log('Asking for static/data/spheres/' + res + '.obj'); @@ -70,12 +70,15 @@ module.exports = function(io) { line = lines[++index]; } } - if (!line) { - socket.emit('finished'); - } socket.emit('elements', toSend); + if (!line) { + // socket.emit('finished'); + socket.disconnect(); + } + + }); }); });