Principle of progressive streaming... needs octree now :s
This commit is contained in:
parent
0b4c01d3e0
commit
f808aebe4f
|
@ -62,6 +62,8 @@ geo.MeshStreamer = function(path, callback) {
|
|||
// Returns the function that compares two faces
|
||||
geo.MeshStreamer.prototype.faceComparator = function(camera) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var direction = {
|
||||
x: camera.target.x - camera.position.x,
|
||||
y: camera.target.y - camera.position.y,
|
||||
|
@ -250,6 +252,14 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
|
||||
});
|
||||
|
||||
socket.on('materials', function() {
|
||||
|
||||
var data = self.nextMaterials();
|
||||
|
||||
socket.emit('elements', data);
|
||||
|
||||
});
|
||||
|
||||
socket.on('next', function(camera) {
|
||||
|
||||
|
||||
|
@ -267,6 +277,30 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
});
|
||||
}
|
||||
|
||||
geo.MeshStreamer.prototype.nextMaterials = function() {
|
||||
|
||||
var data = [];
|
||||
|
||||
for (var i = 0; i < this.meshes.length; i++) {
|
||||
|
||||
var currentMesh = this.meshes[i];
|
||||
|
||||
// Send usemtl
|
||||
data.push([
|
||||
'u',
|
||||
currentMesh.material,
|
||||
currentMesh.vertices.length,
|
||||
currentMesh.faces.length,
|
||||
this.texCoords.length > 0,
|
||||
this.normals.length > 0
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
geo.MeshStreamer.prototype.nextElements = function(_camera) {
|
||||
|
||||
// Prepare camera (and scale to model)
|
||||
|
@ -299,14 +333,17 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
|
|||
var sent = 0;
|
||||
var data = [];
|
||||
|
||||
// Sort faces
|
||||
this.orderedFaces.sort(this.faceComparator(camera));
|
||||
|
||||
var mightBeCompletetlyFinished = true;
|
||||
|
||||
for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
|
||||
for (var faceIndex = 0; faceIndex < this.orderedFaces.length; faceIndex++) {
|
||||
|
||||
var currentMesh = this.meshes[meshIndex];
|
||||
var currentFace = this.orderedFaces[faceIndex];
|
||||
var currentMesh = this.meshes[currentFace.meshIndex];
|
||||
|
||||
if (currentMesh.isFinished()) {
|
||||
if (currentFace.sent) {
|
||||
|
||||
continue;
|
||||
|
||||
|
@ -316,32 +353,6 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
|
|||
|
||||
}
|
||||
|
||||
for (var faceIndex = 0; faceIndex < currentMesh.faces.length; faceIndex++) {
|
||||
|
||||
var currentFace = currentMesh.faces[faceIndex];
|
||||
|
||||
if (currentFace.sent) {
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
if (!currentMesh.started) {
|
||||
|
||||
// Send usemtl
|
||||
data.push([
|
||||
'u',
|
||||
currentMesh.material,
|
||||
currentMesh.vertices.length,
|
||||
currentMesh.faces.length,
|
||||
this.texCoords.length > 0,
|
||||
this.normals.length > 0
|
||||
]);
|
||||
sent++;
|
||||
currentMesh.started = true;
|
||||
|
||||
}
|
||||
|
||||
var vertex1 = this.vertices[currentFace.a];
|
||||
var vertex2 = this.vertices[currentFace.b];
|
||||
var vertex3 = this.vertices[currentFace.c];
|
||||
|
@ -471,8 +482,6 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return {data: data, finished: mightBeCompletetlyFinished};
|
||||
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
|
|||
|
||||
this.socket.on('ok', function() {
|
||||
console.log('ok');
|
||||
self.socket.emit('next', self.getCamera());
|
||||
self.socket.emit('materials');
|
||||
});
|
||||
|
||||
this.socket.on('elements', function(arr) {
|
||||
|
|
Loading…
Reference in New Issue