A lot of stuff, I'm completely lost 😢

This commit is contained in:
Thomas FORGIONE
2015-10-26 15:56:18 +01:00
parent 8ed2b18d49
commit 4768a3056c
14 changed files with 274 additions and 96 deletions

View File

@@ -139,6 +139,10 @@ function resizeElements() {
var obj = arguments[i];
if (obj == null) {
return;
}
if (obj instanceof Element) {
obj.style.width = width + 'px';
@@ -162,7 +166,8 @@ function appendTo(container) {
for (var i = 0; i < arguments.length; i++) {
container.appendChild(arguments[i].domElement);
if (arguments[i] != null)
container.appendChild(arguments[i].domElement);
}

View File

@@ -14,7 +14,9 @@ L3D.ProgressiveLoader.onFinished = function() {
coins[i].mesh.visible = true;
}
loadingCanvas.clear();
if (initMainScene !== L3D.initSponza)
loadingCanvas.clear();
L3D.DB.enable();
camera1.reset();
};
@@ -34,6 +36,7 @@ var coins = [];
var previousTime;
var pointer;
var startCanvas;
var loadingCanvas;
window.onbeforeunload = function() {
@@ -74,7 +77,8 @@ function main() {
Coin.update(true);
loadingCanvas.render();
if (initMainScene !== L3D.initSponza)
loadingCanvas.render();
if (locked !== undefined && locked)
startCanvas.render();
@@ -146,7 +150,8 @@ function initCanvases() {
// Init start canvas
startCanvas = new L3D.StartCanvas(camera1);
loadingCanvas = new L3D.LoadingCanvas();
if (initMainScene !== L3D.initSponza)
loadingCanvas = new L3D.LoadingCanvas();
}
function initModels() {

View File

@@ -52,6 +52,8 @@ L3D.ReplayCamera.prototype.update = function(time) {
// // Nothing to do
// }
}
return this.finished;
};
L3D.ReplayCamera.prototype.linearMotion = function(time) {
@@ -95,6 +97,7 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
// Finished
if (this.counter >= this.path.length) {
this.started = false;
this.finished = true;
// console.log('The replay is finished');
if (typeof this.callback === 'function') {
this.callback();
@@ -113,21 +116,23 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
if (this.coins[i].id === this.event.id)
this.coins[i].get();
}
this.nextEvent();
// Wait a little before launching nextEvent
(function(self) {
setTimeout(function() {
self.nextEvent();
},500);
})(this);
// (function(self) {
// setTimeout(function() {
// self.nextEvent();
// },500);
// })(this);
} else if (this.event.type == 'arrow') {
this.moveHermite(this.cameras[this.event.id]);
} else if (this.event.type == 'reset') {
this.reset();
(function (self) {
setTimeout(function() {
self.nextEvent();
},500);
})(this);
this.nextEvent();
//(function (self) {
// setTimeout(function() {
// self.nextEvent();
// },500);
//})(this);
} else if (this.event.type == 'previousnext') {
this.move(this.event);
} else {
@@ -205,3 +210,38 @@ L3D.ReplayCamera.prototype.moveHermite = function(recommendation) {
};
L3D.ReplayCamera.prototype.save = function() {};
/**
* Creates a list containing all the elements to send to the server to stream visible part
* @return {Array} A list containing <ol start="0">
* <li>the position of the camera</li>
* <li>the target of the camera</li>
* <li>and planes defining the frustum of the camera (a,b,c, and d from ax+by+cz+d=0)</li>
* </ol>
*/
L3D.ReplayCamera.prototype.toList = function() {
this.updateMatrix();
this.updateMatrixWorld();
var frustum = new THREE.Frustum();
var projScreenMatrix = new THREE.Matrix4();
projScreenMatrix.multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse);
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse));
var ret =
[[this.position.x, this.position.y, this.position.z],
[this.target.x, this.target.y, this.target.z]];
for (var i = 0; i < frustum.planes.length; i++) {
var p = frustum.planes[i];
ret.push([
p.normal.x, p.normal.y, p.normal.z, p.constant
]);
}
return ret;
};

View File

@@ -88,7 +88,7 @@ var _parseList = function(arr) {
* @constructor
* @memberOf L3D
*/
var ProgressiveLoader = function(path, scene, camera, callback, log) {
var ProgressiveLoader = function(path, scene, camera, callback, log, laggy) {
/**
* Path to the .obj file
@@ -118,6 +118,11 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
*/
this.callback = callback;
/**
* Boolean indicate that we want extra lag for testing purposes
*/
this.laggy = laggy;
/**
* Group where the sub-objects will be added
* @type {THREE.Object3D}
@@ -169,7 +174,7 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
* Socket to connect to get the mesh
* @type {socket}
*/
this.socket = typeof io === 'function' ? io() : require('socket.io-client').connect('http://localhost:4000');
this.socket = typeof io === 'function' ? io() : require('socket.io-client').connect('http://localhost:4000', {multiplex: false});
this.initIOCallbacks();
@@ -240,7 +245,7 @@ ProgressiveLoader.prototype.getCamera = function() {
if (this.camera === null)
return null;
return this.toList();
return this.camera.toList();
};
/**
@@ -365,7 +370,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
self.meshes[elt.mesh].geometry.normalsNeedUpdate = true;
self.meshes[elt.mesh].geometry.groupsNeedUpdate = true;
if (self.meshes[elt.mesh].faceNumber === self.meshes[elt.mesh].geometry.faces.length) {
if (self.meshes[elt.mesh].faceNumber === self.meshes[elt.mesh].geometry.faces.length || typeof module === 'object') {
self.meshes[elt.mesh].geometry.computeBoundingSphere();
@@ -382,7 +387,11 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
}
// Ask for next elements
self.socket.emit('next', self.getCamera());
if (!self.laggy) {
self.socket.emit('next', self.getCamera());
} else {
setTimeout(function() { self.socket.emit('next', self.getCamera());}, 100);
}
});
this.socket.on('disconnect', function() {
@@ -405,7 +414,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
* Starts the communication with the server
*/
ProgressiveLoader.prototype.start = function() {
this.socket.emit('request', this.objPath);
this.socket.emit('request', this.objPath, this.laggy);
};
return ProgressiveLoader;

View File

@@ -25,7 +25,7 @@ t = [0,1];
f = [0,1];
fp = [-1,-1];
var hermite = new Hermite.special.Polynom(0, 1, -1);
var hermite = new L3D.Hermite.special.Polynom(0, 1, -1);
print('M = [');
for (var t = 0; t < 1; t += 0.01) {

View File

@@ -8,6 +8,8 @@ L3D.BaseRecommendation = function() {
THREE.Object3D.apply(this);
this.camera = new THREE.PerspectiveCamera();
this.camera.position.copy(arguments[4]);
this.camera.target = arguments[5];
};

View File

@@ -1,3 +1,6 @@
var Reco = (typeof Recommendation !== 'undefined' ? Recommendation : L3D.BaseRecommendation);
var Recommendation = Reco;
L3D.LogFunction = function(a,b) {
var val = 100*a/b;
$('.progress-bar').css('width', val+'%').attr('aria-valuenow', val);
@@ -112,7 +115,7 @@ L3D.initZeldaScene = function(scene, collidableObjects, loader) {
L3D.createPeachRecommendations = function(width, height, rec) {
var recos = [];
var Reco = rec !== undefined ? rec : Recommendation;
var Reco = rec !== undefined ? rec : (typeof Recommendation !== 'undefined' ? Recommendation : L3D.BaseRecommendation);
var createRecommendation = function(position, target) {
return new Reco(

View File

@@ -43,7 +43,7 @@ L3D.DB.Private.sendData = function(url, data, force) {
*/
if (typeof module === 'object')
DB_DISABLED = true;
L3D.DB.Private.enabled = !DB_DISABLED;
L3D.DB.Private.enabled = typeof DB_DISABLED === 'undefined' ? true : !DB_DISABLED;
/**
* Enables the requests