From 34b312ae3be75a72fdbde23c28ca84d498d35f83 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Wed, 10 Jun 2015 14:48:11 +0200 Subject: [PATCH] Optimization attempt --- js/ProgressiveLoader.js | 25 +++++++------------------ socket.js | 15 +++++++++------ 2 files changed, 16 insertions(+), 24 deletions(-) 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(); + } + + }); }); });