2015-06-09 17:36:21 +02:00
|
|
|
var ProgressiveLoader = function(res, scene) {
|
|
|
|
// Create mesh
|
|
|
|
var geometry = new THREE.Geometry();
|
|
|
|
geometry.dynamic = true;
|
|
|
|
var material = new THREE.MeshLambertMaterial();
|
|
|
|
material.color.setRGB(1,0,0);
|
|
|
|
material.side = THREE.DoubleSide;
|
|
|
|
var mesh = new THREE.Mesh(geometry, material);
|
|
|
|
mesh.up = new THREE.Vector3(0,0,1);
|
|
|
|
var added = false;
|
2015-06-10 11:24:59 +02:00
|
|
|
var finished = false;
|
2015-06-09 17:36:21 +02:00
|
|
|
|
2015-06-09 17:54:38 +02:00
|
|
|
var socket = io();
|
2015-06-09 17:36:21 +02:00
|
|
|
|
|
|
|
socket.emit('request', res);
|
|
|
|
|
2015-06-10 11:24:59 +02:00
|
|
|
socket.on('ok', function() {
|
|
|
|
socket.emit('next');
|
|
|
|
});
|
|
|
|
|
2015-06-09 17:36:21 +02:00
|
|
|
socket.on('vertex', function(arr) {
|
2015-06-10 11:24:59 +02:00
|
|
|
// console.log('v(', arr[0], ')', arr[1], arr[2], arr[3]);
|
2015-06-09 17:36:21 +02:00
|
|
|
mesh.geometry.vertices[arr[0]] = new THREE.Vector3(arr[1], arr[2], arr[3]);
|
|
|
|
mesh.geometry.verticesNeedUpdate = true;
|
2015-06-10 11:24:59 +02:00
|
|
|
socket.emit('next');
|
2015-06-09 17:36:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('face', function(arr) {
|
2015-06-10 11:24:59 +02:00
|
|
|
// console.log('f', arr[0], arr[1], arr[2]);
|
2015-06-09 17:36:21 +02:00
|
|
|
mesh.geometry.faces.push(new THREE.Face3(arr[0], arr[1], arr[2]));
|
|
|
|
|
2015-06-10 11:24:59 +02:00
|
|
|
// if (arr[0] >= mesh.geometry.vertices.length
|
|
|
|
// || arr[1] >= mesh.geometry.vertices.length
|
|
|
|
// || arr[2] >= mesh.geometry.vertices.length) {
|
2015-06-09 17:36:21 +02:00
|
|
|
|
2015-06-10 11:24:59 +02:00
|
|
|
// console.log("Error");
|
|
|
|
// }
|
2015-06-09 17:36:21 +02:00
|
|
|
|
|
|
|
if (arr[3])
|
|
|
|
mesh.geometry.faces.push(new THREE.Face3(arr[0], arr[2], arr[3]));
|
|
|
|
|
|
|
|
if (!added) {
|
|
|
|
scene.add(mesh);
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the normal
|
|
|
|
|
|
|
|
mesh.geometry.verticesNeedUpdate = true;
|
|
|
|
mesh.geometry.groupsNeedUpdate = true;
|
|
|
|
mesh.geometry.elementsNeedUpdate = true;
|
|
|
|
mesh.geometry.normalsNeedUpdate = true;
|
|
|
|
|
2015-06-10 11:24:59 +02:00
|
|
|
if (finished) {
|
2015-06-09 17:36:21 +02:00
|
|
|
console.log("Finished");
|
2015-06-10 11:24:59 +02:00
|
|
|
} else {
|
|
|
|
socket.emit('next');
|
2015-06-09 17:36:21 +02:00
|
|
|
}
|
2015-06-10 11:24:59 +02:00
|
|
|
mesh.geometry.computeFaceNormals();
|
2015-06-09 17:36:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('finished', function(arg) {
|
2015-06-10 11:24:59 +02:00
|
|
|
finished = true;
|
2015-06-09 17:36:21 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2015-06-10 11:24:59 +02:00
|
|
|
socket.on('none', function() {
|
|
|
|
socket.emit('next');
|
|
|
|
});
|
|
|
|
|
2015-06-09 17:36:21 +02:00
|
|
|
return mesh;
|
|
|
|
}
|