Now, only the part of the mesh in front of the camera is streamed

The rest is definitly lost
This commit is contained in:
Thomas FORGIONE
2015-06-17 17:11:23 +02:00
parent d8e5d106d2
commit bfca8ceab1
5 changed files with 130 additions and 31 deletions

View File

@@ -63,7 +63,7 @@ var _parseList = function(arr) {
return ret;
}
var ProgressiveLoader = function(path, scene, callback) {
var ProgressiveLoader = function(path, scene, camera, callback) {
// Init attributes
this.objPath = path.substring(1, path.length);
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/';
@@ -87,6 +87,8 @@ var ProgressiveLoader = function(path, scene, callback) {
this.socket = io();
this.initIOCallbacks();
this.camera = camera;
}
ProgressiveLoader.prototype.load = function() {

View File

@@ -1,4 +1,4 @@
var _parseList = function(arr) {
var _parseList2 = function(arr) {
var ret = {};
ret.index = arr[1];
@@ -14,11 +14,12 @@ var _parseList = function(arr) {
ret.y = arr[3];
} else if (arr[0] === 'f') {
ret.type = 'face';
ret.mesh = arr[2];
// Only Face3 are allowed
vertexIndices = arr[2];
textureIndices = arr[3];
normalIndices = arr[4];
vertexIndices = arr[3];
textureIndices = arr[4];
normalIndices = arr[5];
// Vertex indices
ret.a = vertexIndices[0];
@@ -63,7 +64,7 @@ var _parseList = function(arr) {
return ret;
}
var ProgressiveLoaderGeometry = function(path, scene, callback) {
var ProgressiveLoaderGeometry = function(path, scene, camera, callback) {
// Init attributes
this.objPath = path.substring(1, path.length);
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/';
@@ -88,6 +89,8 @@ var ProgressiveLoaderGeometry = function(path, scene, callback) {
this.socket = io();
this.initIOCallbacks();
this.camera = camera;
}
ProgressiveLoaderGeometry.prototype.load = function() {
@@ -105,13 +108,20 @@ ProgressiveLoaderGeometry.prototype.load = function() {
});
}
ProgressiveLoaderGeometry.prototype.getCamera = function() {
return [this.camera.position.x, this.camera.position.y, this.camera.position.z,
this.camera.target.x, this.camera.target.y, this.camera.target.z];
}
ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
var self = this;
this.socket.on('ok', function() {
console.log('ok');
self.socket.emit('next');
self.socket.emit('next', self.getCamera());
});
this.socket.on('elements', function(arr) {
@@ -119,7 +129,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
// console.log("Received elements for the " + (++self.counter) + "th time !");
for (var i = 0; i < arr.length; i++) {
var elt = _parseList(arr[i]);
var elt = _parseList2(arr[i]);
// console.log(elts);
if (elt.type === 'vertex') {
@@ -204,25 +214,25 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
} else if (elt.type === 'face') {
self.currentMesh.geometry.faces.push(new THREE.Face3(elt.a, elt.b, elt.c, [self.normals[elt.aNormal], self.normals[elt.bNormal], self.normals[elt.cNormal]]));
self.obj.children[elt.mesh].geometry.faces.push(new THREE.Face3(elt.a, elt.b, elt.c, [self.normals[elt.aNormal], self.normals[elt.bNormal], self.normals[elt.cNormal]]));
if (elt.aTexture !== undefined) {
self.currentMesh.geometry.faceVertexUvs[0].push([self.texCoords[elt.aTexture], self.texCoords[elt.bTexture], self.texCoords[elt.cTexture]]);
self.obj.children[elt.mesh].geometry.faceVertexUvs[0].push([self.texCoords[elt.aTexture], self.texCoords[elt.bTexture], self.texCoords[elt.cTexture]]);
}
self.currentMesh.geometry.verticesNeedUpdate = true;
self.currentMesh.geometry.uvsNeedUpdate = true;
self.currentMesh.geometry.normalsNeedUpdate = true;
self.currentMesh.geometry.groupsNeedUpdate = true;
self.obj.children[elt.mesh].geometry.verticesNeedUpdate = true;
self.obj.children[elt.mesh].geometry.uvsNeedUpdate = true;
self.obj.children[elt.mesh].geometry.normalsNeedUpdate = true;
self.obj.children[elt.mesh].geometry.groupsNeedUpdate = true;
}
}
// Ask for next elements
self.socket.emit('next');
self.socket.emit('next', self.getCamera());
});
this.socket.on('disconnect', function() {

View File

@@ -11,11 +11,12 @@ function addLight(scene) {
scene.add(ambient_light);
}
function initPeachCastle(scene, collidableObjects, loader, static_path) {
function initPeachCastle(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader(
'/static/data/castle/princess peaches castle (outside).obj',
scene,
camera,
function(object) {
object.raycastable = true;
if (object.material.name === 'Material.103_princess_peaches_cast') {
@@ -47,7 +48,7 @@ function initPeach(camera, scene, static_path, coins) {
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initPeachCastle(scene, collidableObjects, loader, static_path);
initPeachCastle(scene, collidableObjects, loader, camera);
camera.resetElements = resetPeachElements();
camera.collidableObjects = collidableObjects;
@@ -159,11 +160,12 @@ function createPeachCameras(width, height) {
return cams;
}
function initBobombScene(scene, collidableObjects, loader, static_path) {
function initBobombScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader(
static_path + 'data/bobomb/bobomb battlefeild.obj',
scene,
camera,
function(object) {
object.raycastable = true;
if (object.material.name === 'Material.071_574B138E_c.bmp' ||
@@ -276,7 +278,7 @@ function initBobomb(camera, scene, static_path, coins) {
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initBobombScene(scene, collidableObjects, loader, static_path);
initBobombScene(scene, collidableObjects, loader, camera);
camera.resetElements = resetBobombElements();
camera.collidableObjects = collidableObjects;
@@ -304,11 +306,12 @@ function initBobomb(camera, scene, static_path, coins) {
return cameras;
}
function initWhompScene(scene, collidableObjects, loader, static_path) {
function initWhompScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader(
static_path + 'data/whomp/Whomps Fortress.obj',
scene,
camera,
function(object) {
if (object.material.name === 'Shape_088' ||
object.material.name === 'Shape_089') {
@@ -426,7 +429,7 @@ function initWhomp(camera, scene, static_path, coins) {
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initWhompScene(scene, collidableObjects, loader, static_path);
initWhompScene(scene, collidableObjects, loader, camera);
camera.resetElements = resetWhompElements();
camera.collidableObjects = collidableObjects;
@@ -454,11 +457,12 @@ function initWhomp(camera, scene, static_path, coins) {
return cameras;
}
function initMountainScene(scene, collidableObjects, loader, static_path) {
function initMountainScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoader(
static_path + 'data/mountain/coocoolmountain.obj',
scene,
camera,
function(object) {
// object.rotation.x = -Math.PI/2;
// object.rotation.z = Math.PI/2;
@@ -578,7 +582,7 @@ function initMountain(camera, scene, static_path, coins) {
var loader = new THREE.OBJMTLLoader();
var collidableObjects = [];
initMountainScene(scene, collidableObjects, loader, static_path);
initMountainScene(scene, collidableObjects, loader, camera);
camera.resetElements = resetMountainElements();
camera.collidableObjects = collidableObjects;
@@ -605,9 +609,9 @@ function initMountain(camera, scene, static_path, coins) {
return cameras;
}
function initSponzaScene(scene, collidableObjects, loader, static_path) {
function initSponzaScene(scene, collidableObjects, loader, camera) {
var loader = new ProgressiveLoaderGeometry('/static/data/sponza/sponza.obj', scene, function(obj) {
var loader = new ProgressiveLoaderGeometry('/static/data/sponza/sponza.obj', scene, camera, function(obj) {
if (obj.material.name === 'chain' ||
obj.material.name === 'leaf' ||
obj.material.name === 'Material__57') {
@@ -620,6 +624,7 @@ function initSponzaScene(scene, collidableObjects, loader, static_path) {
});
l = loader;
loader.load();
loader.obj.scale.set(0.1,0.1,0.1);
@@ -665,7 +670,7 @@ function initSponza(camera, scene, static_path, coins) {
var loader = new THREE.JSONLoader();
var collidableObjects = [];
initSponzaScene(scene, collidableObjects, loader, static_path);
initSponzaScene(scene, collidableObjects, loader, camera);
camera.resetElements = resetSponzaElements();
camera.collidableObjects = collidableObjects;