Stream int instead of strings (I hope)

This commit is contained in:
Thomas FORGIONE 2015-06-10 14:31:16 +02:00
parent c6f75a6b0b
commit 0272477503
2 changed files with 43 additions and 23 deletions

View File

@ -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]
));
}

View File

@ -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];
}
}