diff --git a/geo/MeshStreamer.js b/geo/MeshStreamer.js index 5cb0893..9f26798 100644 --- a/geo/MeshStreamer.js +++ b/geo/MeshStreamer.js @@ -56,6 +56,12 @@ function partialSort(items, k, comparator) { */ geo.MeshStreamer = function(path) { + /** + * array of array telling if the jth face of the ith mesh has already been sent + * @type{Boolean[][]} + */ + this.meshFaces = []; + /** * array of booleans telling if the ith vertex has already been sent * @type {Boolean[]} @@ -186,6 +192,17 @@ geo.MeshStreamer.prototype.start = function(socket) { self.mesh = cont.availableMeshes[path]; + self.meshFaces = new Array(self.mesh.meshes.length); + + for (var i = 0; i < self.meshFaces.length; i++) { + + self.meshFaces[i] = { + counter: 0, + array: new Array(self.mesh.meshes[i].faces.length) + }; + + } + var regex = /.*\.\..*/; var filePath = path.substring(1, path.length); @@ -326,7 +343,7 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) { var currentMesh = this.mesh.meshes[meshIndex]; - if (currentMesh.isFinished()) { + if (this.isFinished(meshIndex)) { continue; @@ -340,7 +357,7 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) { var currentFace = currentMesh.faces[faceIndex]; - if (currentFace.sent) { + if (this.meshFaces[meshIndex].array[faceIndex] === true) { continue; @@ -500,7 +517,9 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) { } data.push(currentFace.toList()); - currentFace.sent = true; + // this.meshFaces[meshIndex] = this.meshFaces[meshIndex] || []; + this.meshFaces[meshIndex].array[faceIndex] = true; + this.meshFaces[meshIndex].counter++; currentMesh.faceIndex++; sent++; @@ -517,4 +536,10 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) { } +geo.MeshStreamer.prototype.isFinished = function(i) { + + return this.meshFaces[i].counter === this.meshFaces[i].array.length; + +} + module.exports = geo; diff --git a/socket.js b/socket.js index 2fe5dfb..33a6fb3 100644 --- a/socket.js +++ b/socket.js @@ -4,6 +4,7 @@ var geo = require('./geo/MeshStreamer.js'); module.exports = function(io) { io.on('connection', function(socket) { + console.log("New MeshStreamer"); var streamer = new geo.MeshStreamer(); streamer.start(socket);