From 027247750345da43ec90f2ce97a503faebb6439b Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Wed, 10 Jun 2015 14:31:16 +0200 Subject: [PATCH] Stream int instead of strings (I hope) --- js/ProgressiveLoader.js | 34 +++++++++++++--------------------- socket.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/js/ProgressiveLoader.js b/js/ProgressiveLoader.js index b29cc9b..db046df 100644 --- a/js/ProgressiveLoader.js +++ b/js/ProgressiveLoader.js @@ -32,46 +32,38 @@ var ProgressiveLoader = function(res, scene) { // We'll receive an array of string (obj) for (var i = 0; i < arr.length; i++) { - var line = arr[i]; + var elts = arr[i]; // console.log(line); - if (line[0] === 'v') { - - var elts = line.split(' '); + if (elts[0] === 'v') { mesh.geometry.vertices.push(new THREE.Vector3( - parseFloat(elts[1]), - parseFloat(elts[2]), - parseFloat(elts[3]) + elts[1], + elts[2], + elts[3] )); mesh.geometry.verticesNeedUpdate = true; - } else if (line[0] === 'f') { - - var elts = line.split(' '); - - elts[1] = parseInt(elts[1]) - 1; - elts[2] = parseInt(elts[2]) - 1; - elts[3] = parseInt(elts[3]) - 1; + } else if (elts[0] === 'f') { if (elts[4]) - elts[4] = parseInt(elts[4]) - 1; + elts[4] = parseInt(elts[4]); mesh.geometry.faces.push(new THREE.Face3( - parseInt(elts[1]), - parseInt(elts[2]), - parseInt(elts[3]) + elts[1], + elts[2], + elts[3] )); // If the face has 4 vertices, create second triangle if (elts[4]) { mesh.geometry.faces.push(new THREE.Face3( - parseInt(elts[1]), - parseInt(elts[3]), - parseInt(elts[4]) + elts[1], + elts[3], + elts[4] )); } diff --git a/socket.js b/socket.js index 67db414..d432bfe 100644 --- a/socket.js +++ b/socket.js @@ -1,6 +1,34 @@ var fs = require('fs'); var sleep = require('sleep'); +function parseLine(line) { + var elts = line.split(' '); + if (elts[0] === 'v') { + + return [ + 'v', + parseFloat(elts[1]), + parseFloat(elts[2]), + parseFloat(elts[3]) + ]; + + } else if (elts[0] === 'f') { + + var tmp = [ + 'f', + parseInt(elts[1]) - 1, + parseInt(elts[2]) - 1, + parseInt(elts[3]) - 1 + ]; + + if (elts[4]) { + tmp.push(parseInt(elts[4]) - 1); + } + + return tmp; + } +} + module.exports = function(io) { io.on('connection', function(socket) { @@ -33,12 +61,12 @@ module.exports = function(io) { for (var i = 0; i < 50; i++) { while (line && line[0] !== 'f') { - toSend.push(line); + toSend.push(parseLine(line)); line = lines[++index]; } if (line && line[0] === 'f') { - toSend.push(line); + toSend.push(parseLine(line)); line = lines[++index]; } }