Should work but seems slow
This commit is contained in:
@@ -22,6 +22,10 @@ L3D.ReplayCamera = function() {
|
||||
this.theta = Math.PI;
|
||||
this.phi = Math.PI;
|
||||
|
||||
this.shouldRecover = false;
|
||||
|
||||
this.recommendationClicked = null;
|
||||
|
||||
};
|
||||
L3D.ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
|
||||
L3D.ReplayCamera.prototype.constructor = L3D.ReplayCamera;
|
||||
@@ -71,10 +75,17 @@ L3D.ReplayCamera.prototype.cameraMotion = function(time) {
|
||||
var tmp = L3D.Tools.sum(L3D.Tools.mul(this.oldPosition, 1-this.t), L3D.Tools.mul(this.newPosition, this.t));
|
||||
this.position.copy(tmp);
|
||||
this.target = L3D.Tools.sum(L3D.Tools.mul(this.oldTarget, 1-this.t), L3D.Tools.mul(this.newTarget, this.t));
|
||||
this.t += 1 / (((new Date(this.path[this.counter].time)).getTime() - (new Date(this.path[this.counter-1].time)).getTime()) / 20);
|
||||
this.t += this.recovering ? 0.01 : 1 / (((new Date(this.path[this.counter].time)).getTime() - (new Date(this.path[this.counter-1].time)).getTime()) / 20);
|
||||
|
||||
if (this.t > 1) {
|
||||
this.nextEvent();
|
||||
this.recommendationClicked = null;
|
||||
if (typeof this.recoverCallback === 'function') {
|
||||
this.recoverCallback();
|
||||
this.recoverCallback = null;
|
||||
} else {
|
||||
this.nextEvent();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -87,11 +98,15 @@ L3D.ReplayCamera.prototype.hermiteMotion = function(time) {
|
||||
this.t += 0.01 * time / 20;
|
||||
|
||||
if (this.t > 1) {
|
||||
this.recommendationClicked = null;
|
||||
this.nextEvent();
|
||||
}
|
||||
};
|
||||
|
||||
L3D.ReplayCamera.prototype.nextEvent = function() {
|
||||
|
||||
var self = this;
|
||||
|
||||
this.counter++;
|
||||
|
||||
// Finished
|
||||
@@ -124,7 +139,22 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
|
||||
// },500);
|
||||
// })(this);
|
||||
} else if (this.event.type == 'arrow') {
|
||||
this.moveHermite(this.cameras[this.event.id]);
|
||||
if (this.shouldRecover) {
|
||||
(function(self, tmp) {
|
||||
self.event.type = 'camera';
|
||||
self.recovering = true;
|
||||
self.move({
|
||||
position: self.position.clone(),
|
||||
target: self.cameras[self.event.id].camera.position.clone()
|
||||
}, function() {
|
||||
self.recovering = false;
|
||||
self.event.type = 'arrow';
|
||||
self.moveReco(tmp);
|
||||
});
|
||||
})(this, this.event.id);
|
||||
} else {
|
||||
this.moveReco(this.event.id);
|
||||
}
|
||||
} else if (this.event.type == 'reset') {
|
||||
this.reset();
|
||||
this.nextEvent();
|
||||
@@ -176,7 +206,13 @@ L3D.ReplayCamera.prototype.anglesFromVectors = function() {
|
||||
this.theta = Math.atan2(forward.x, forward.z);
|
||||
};
|
||||
|
||||
L3D.ReplayCamera.prototype.move = function(recommendation) {
|
||||
L3D.ReplayCamera.prototype.move = function(recommendation, callback) {
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
|
||||
this.recoverCallback = callback;
|
||||
|
||||
}
|
||||
|
||||
var otherCamera = recommendation.camera || recommendation;
|
||||
|
||||
@@ -185,12 +221,17 @@ L3D.ReplayCamera.prototype.move = function(recommendation) {
|
||||
this.oldPosition = this.position.clone();
|
||||
this.newTarget = new THREE.Vector3(otherCamera.target.x, otherCamera.target.y, otherCamera.target.z);
|
||||
this.newPosition = new THREE.Vector3(otherCamera.position.x, otherCamera.position.y, otherCamera.position.z);
|
||||
|
||||
this.t = 0;
|
||||
|
||||
};
|
||||
|
||||
L3D.ReplayCamera.prototype.moveHermite = function(recommendation) {
|
||||
|
||||
if (this.shouldRecover === false) {
|
||||
this.shouldRecover = true;
|
||||
}
|
||||
|
||||
var otherCamera = recommendation.camera || recommendation;
|
||||
|
||||
this.movingHermite = true;
|
||||
@@ -209,6 +250,14 @@ L3D.ReplayCamera.prototype.moveHermite = function(recommendation) {
|
||||
);
|
||||
};
|
||||
|
||||
L3D.ReplayCamera.prototype.moveReco = function(recommendationId) {
|
||||
|
||||
this.recommendationClicked = this.cameras[recommendationId].camera;
|
||||
|
||||
this.moveHermite(this.cameras[recommendationId]);
|
||||
|
||||
};
|
||||
|
||||
L3D.ReplayCamera.prototype.save = function() {};
|
||||
|
||||
/**
|
||||
@@ -220,18 +269,23 @@ L3D.ReplayCamera.prototype.save = function() {};
|
||||
* </ol>
|
||||
*/
|
||||
L3D.ReplayCamera.prototype.toList = function() {
|
||||
this.updateMatrix();
|
||||
this.updateMatrixWorld();
|
||||
|
||||
var camera = (this.recommendationClicked === null ? this : this.recommendationClicked);
|
||||
|
||||
camera.updateMatrix();
|
||||
camera.updateMatrixWorld();
|
||||
|
||||
var frustum = new THREE.Frustum();
|
||||
var projScreenMatrix = new THREE.Matrix4();
|
||||
projScreenMatrix.multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse);
|
||||
projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
||||
|
||||
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse));
|
||||
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
|
||||
|
||||
var ret =
|
||||
[[this.position.x, this.position.y, this.position.z],
|
||||
[this.target.x, this.target.y, this.target.z]];
|
||||
[[camera.position.x, camera.position.y, camera.position.z],
|
||||
[camera.target.x, camera.target.y, camera.target.z],
|
||||
this.recommendationClicked !== null
|
||||
];
|
||||
|
||||
for (var i = 0; i < frustum.planes.length; i++) {
|
||||
|
||||
|
||||
@@ -90,6 +90,8 @@ var _parseList = function(arr) {
|
||||
*/
|
||||
var ProgressiveLoader = function(path, scene, camera, callback, log, laggy) {
|
||||
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* Path to the .obj file
|
||||
* @type {string}
|
||||
@@ -184,6 +186,12 @@ var ProgressiveLoader = function(path, scene, camera, callback, log, laggy) {
|
||||
*/
|
||||
this.camera = camera;
|
||||
|
||||
this.camera._moveReco = this.camera.moveReco;
|
||||
|
||||
this.camera.moveReco = function(param) {
|
||||
self.socket.emit('reco', param);
|
||||
self.camera._moveReco.apply(self.camera, arguments);
|
||||
};
|
||||
|
||||
/**
|
||||
* Number of total elements for loading
|
||||
@@ -210,6 +218,14 @@ var ProgressiveLoader = function(path, scene, camera, callback, log, laggy) {
|
||||
*/
|
||||
this.log = log;
|
||||
|
||||
this.mapFace = {};
|
||||
|
||||
};
|
||||
|
||||
ProgressiveLoader.prototype.hasFace = function(face) {
|
||||
|
||||
return this.mapFace[(face.a) + '-' + (face.b) + '-' + (face.c)] === true;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -376,6 +392,8 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||
|
||||
}
|
||||
|
||||
self.mapFace[elt.a + '-' + elt.b + '-' + elt.c] = true;
|
||||
|
||||
|
||||
} else if (elt.type === 'global') {
|
||||
|
||||
@@ -386,6 +404,10 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||
|
||||
}
|
||||
|
||||
if (typeof self.onBeforeEmit === 'function') {
|
||||
self.onBeforeEmit();
|
||||
}
|
||||
|
||||
// Ask for next elements
|
||||
if (!self.laggy) {
|
||||
self.socket.emit('next', self.getCamera());
|
||||
@@ -396,7 +418,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||
|
||||
this.socket.on('disconnect', function() {
|
||||
if (typeof self.log === 'function')
|
||||
self.log(self.numberOfFacesReceived, self.numberOfFaces);
|
||||
self.log(self.numberOfFaces, self.numberOfFaces);
|
||||
self.finished = true;
|
||||
|
||||
if (typeof L3D.ProgressiveLoader.onFinished === 'function') {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
L3D.ArrowRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
|
||||
|
||||
L3D.BaseRecommendation.apply(this);
|
||||
L3D.BaseRecommendation.apply(this, arguments);
|
||||
|
||||
/**
|
||||
* @type {L3D.FixedCamera}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
L3D.BaseRecommendation = function() {
|
||||
|
||||
THREE.Object3D.apply(this);
|
||||
THREE.Object3D.apply(this, arguments);
|
||||
|
||||
this.camera = new THREE.PerspectiveCamera();
|
||||
this.camera.position.copy(arguments[4]);
|
||||
|
||||
@@ -712,11 +712,27 @@ L3D.initSponzaScene = function(scene, collidableObjects, recommendation, clickab
|
||||
|
||||
};
|
||||
|
||||
L3D.createSponzaCoins = function() {
|
||||
return [];
|
||||
L3D.createSponzaRecommendations = function(width, height) {
|
||||
var createRecommendation = function(position, target) {
|
||||
return new Recommendation(
|
||||
50,
|
||||
width / height,
|
||||
1,
|
||||
100000,
|
||||
position,
|
||||
target
|
||||
);
|
||||
};
|
||||
|
||||
return [
|
||||
createRecommendation(
|
||||
new THREE.Vector3(97.36225946503932,10.925697484337014,12.852363038244272),
|
||||
new THREE.Vector3(133.315101552449,18.576354168001703,-2.9229530646577633)
|
||||
)
|
||||
];
|
||||
};
|
||||
|
||||
L3D.createSponzaRecommendations = function() {
|
||||
L3D.createSponzaCoins = function() {
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user