Some commits
This commit is contained in:
parent
9c1aca171f
commit
fa1636ac8e
|
@ -0,0 +1,116 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
require('app-module-path').addPath(__dirname + '/../../server/lib');
|
||||||
|
|
||||||
|
// REQUIRES AND INITS
|
||||||
|
let width = Math.floor(1134) // /10);
|
||||||
|
let height = Math.floor(768 ) // /10);
|
||||||
|
|
||||||
|
let XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
|
||||||
|
let THREE = require('three');
|
||||||
|
let Coin = require('./Coin.js');
|
||||||
|
let L3D = require('../../static/js/l3d.min.js');
|
||||||
|
let fs = require('fs');
|
||||||
|
|
||||||
|
let Matrix = require('Matrix');
|
||||||
|
let Serial = require('Serial');
|
||||||
|
|
||||||
|
let scene = new THREE.Scene();
|
||||||
|
let geometry = new THREE.Geometry();
|
||||||
|
|
||||||
|
let peach = new THREE.Object3D();
|
||||||
|
let bobomb = new THREE.Object3D();
|
||||||
|
let whomp = new THREE.Object3D();
|
||||||
|
let mountain = new THREE.Object3D();
|
||||||
|
|
||||||
|
var finished = false;
|
||||||
|
let frame = 0;
|
||||||
|
let raycaster = new THREE.Raycaster();
|
||||||
|
|
||||||
|
var total = 0;
|
||||||
|
|
||||||
|
let loader, progLoader;
|
||||||
|
|
||||||
|
let id = process.argv[2] === undefined ? 56 : parseInt(process.argv[2])
|
||||||
|
let laggy = true;
|
||||||
|
|
||||||
|
let info = {};
|
||||||
|
|
||||||
|
|
||||||
|
// INIT COLORS
|
||||||
|
var colors = [[0,0,0]];
|
||||||
|
|
||||||
|
for (let i = 0; i < 856; i++) {
|
||||||
|
colors.push([
|
||||||
|
Math.floor(255*Math.random()),
|
||||||
|
Math.floor(255*Math.random()),
|
||||||
|
Math.floor(255*Math.random())
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var camera; var finished = false;
|
||||||
|
var Recommendation = L3D.BaseRecommendation;
|
||||||
|
var forceFinished = false;
|
||||||
|
main();
|
||||||
|
|
||||||
|
// FUNCTIONS
|
||||||
|
function main() {
|
||||||
|
var path = initElements(id);
|
||||||
|
var outputName = path.split('/');
|
||||||
|
outputName = outputName[outputName.length - 1].replace('.obj', '.json');
|
||||||
|
loader = new L3D.ProgressiveLoader(
|
||||||
|
path, new THREE.Object3D(), null
|
||||||
|
);
|
||||||
|
loader.load(
|
||||||
|
function() {
|
||||||
|
console.log("Loaded");
|
||||||
|
Serial.serializeToFile(outputName, loader.obj);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDistance(old, newP) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
L3D.Tools.norm2(L3D.Tools.diff(old.position, newP.position)) +
|
||||||
|
L3D.Tools.norm2(L3D.Tools.diff(old.target, newP.target)) > 0.1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function initElements(id) {
|
||||||
|
switch (id) {
|
||||||
|
case 1:
|
||||||
|
return '/static/data/castle/princess peaches castle (outside)_sub.obj';
|
||||||
|
case 2:
|
||||||
|
return '/static/data/bobomb/bobomb battlefeild_sub.obj';
|
||||||
|
case 3:
|
||||||
|
return '/static/data/mountain/coocoolmountain_sub.obj';
|
||||||
|
case 4:
|
||||||
|
return '/static/data/whomp/Whomps Fortress_sub.obj';
|
||||||
|
case 5:
|
||||||
|
return '/static/data/sponza/sponza.obj';
|
||||||
|
default:
|
||||||
|
console.err('This sceneId doesn\'t exist');
|
||||||
|
process.exit(-1);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(data) {
|
||||||
|
scene.add(camera);
|
||||||
|
|
||||||
|
camera.reset();
|
||||||
|
camera.speed = 0.001;
|
||||||
|
camera.start();
|
||||||
|
setTimeout(loop, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function equalFaces(face1, face2) { return face1.a === face2.a && face1.b === face2.b && face1.c === face2.c; };
|
||||||
|
|
||||||
|
function printVector(vec) { console.log(`(${vec.x},${vec.y},${vec.z})`); }
|
||||||
|
|
||||||
|
let old;
|
||||||
|
|
|
@ -100,12 +100,13 @@ function objectClickerOnClick(camera1, buttonManager, recommendations, coins) {
|
||||||
} else if (obj instanceof L3D.BaseRecommendation) {
|
} else if (obj instanceof L3D.BaseRecommendation) {
|
||||||
|
|
||||||
obj.check();
|
obj.check();
|
||||||
camera1.moveHermite(obj);
|
|
||||||
|
|
||||||
// Send event to DB
|
// Send event to DB
|
||||||
event = new L3D.DB.Event.ArrowClicked();
|
event = new L3D.DB.Event.ArrowClicked();
|
||||||
event.arrowId = recommendations.indexOf(obj);
|
event.arrowId = recommendations.indexOf(obj);
|
||||||
event.send();
|
event.send();
|
||||||
|
|
||||||
|
camera1.moveHermite(obj, undefined, event.arrowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the button manager
|
// Update the button manager
|
||||||
|
|
|
@ -38,15 +38,15 @@ var pointer;
|
||||||
var startCanvas;
|
var startCanvas;
|
||||||
var loadingCanvas;
|
var loadingCanvas;
|
||||||
|
|
||||||
window.onbeforeunload = function() {
|
// window.onbeforeunload = function() {
|
||||||
|
//
|
||||||
if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza && !($('#next').is(":visible"))) {
|
// if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza && !($('#next').is(":visible"))) {
|
||||||
|
//
|
||||||
return 'Warning : you are going to leave the page and abort the current test !';
|
// return 'Warning : you are going to leave the page and abort the current test !';
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
};
|
// };
|
||||||
|
|
||||||
var nextPage = '/prototype/play';
|
var nextPage = '/prototype/play';
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ function main() {
|
||||||
initModels();
|
initModels();
|
||||||
initListeners();
|
initListeners();
|
||||||
|
|
||||||
appendTo(container)(stats, Coin, startCanvas, pointer, previewer, loadingCanvas, renderer);
|
appendTo(container)(stats, Coin, startCanvas, pointer, previewer, /*loadingCanvas,*/ renderer);
|
||||||
// appendTo(container)(startCanvas, pointer, previewer, renderer);
|
// appendTo(container)(startCanvas, pointer, previewer, renderer);
|
||||||
|
|
||||||
// Set the good size of cameras
|
// Set the good size of cameras
|
||||||
|
@ -117,6 +117,32 @@ function initThreeElements() {
|
||||||
renderer = new THREE.WebGLRenderer({alpha:true, antialias:true});
|
renderer = new THREE.WebGLRenderer({alpha:true, antialias:true});
|
||||||
renderer.setClearColor(0x87ceeb);
|
renderer.setClearColor(0x87ceeb);
|
||||||
|
|
||||||
|
var loader = new THREE.OBJLoader();
|
||||||
|
|
||||||
|
loader.load(
|
||||||
|
'/static/data/coin/Coin.obj',
|
||||||
|
function(object) {
|
||||||
|
object.traverse(function (mesh) {
|
||||||
|
if (mesh instanceof THREE.Mesh) {
|
||||||
|
mesh.scale.set(0.01,0.01,0.01);
|
||||||
|
mesh.material.color.setHex(0xffff00);
|
||||||
|
mesh.geometry.computeVertexNormals();
|
||||||
|
mesh.raycastable = true;
|
||||||
|
mesh.position.copy(new THREE.Vector3(-23.85237224023958,12.30017484578007,2.883526209796364));
|
||||||
|
scene.add(mesh);
|
||||||
|
|
||||||
|
newMesh = mesh.clone();
|
||||||
|
newMesh.position.copy(new THREE.Vector3(-8.225753727064939,11.932703941399415,8.637544772060489));
|
||||||
|
scene.add(newMesh);
|
||||||
|
|
||||||
|
newMesh.position.copy(new THREE.Vector3(18.198980821370327,2.5219742652442885,10.741621475827422));
|
||||||
|
scene.add(newMesh);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize pointer camera
|
// Initialize pointer camera
|
||||||
camera1 = new L3D.PointerCamera(
|
camera1 = new L3D.PointerCamera(
|
||||||
50,
|
50,
|
||||||
|
|
|
@ -167,7 +167,7 @@ L3D.PointerCamera = function() {
|
||||||
* Option to enable or disable the collisions
|
* Option to enable or disable the collisions
|
||||||
* @type {Boolean}
|
* @type {Boolean}
|
||||||
*/
|
*/
|
||||||
this.collisions = true;
|
this.collisions = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is true when we should log the camera angles. It will be set to false
|
* Is true when we should log the camera angles. It will be set to false
|
||||||
|
@ -457,7 +457,7 @@ L3D.PointerCamera.prototype.anglesFromVectors = function() {
|
||||||
* @param {Camera} camera Camera to move to
|
* @param {Camera} camera Camera to move to
|
||||||
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera
|
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera
|
||||||
*/
|
*/
|
||||||
L3D.PointerCamera.prototype.move = function(recommendation, toSave) {
|
L3D.PointerCamera.prototype.move = function(recommendation, toSave, recommendationId) {
|
||||||
if (toSave === undefined)
|
if (toSave === undefined)
|
||||||
toSave = true;
|
toSave = true;
|
||||||
|
|
||||||
|
@ -488,13 +488,13 @@ L3D.PointerCamera.prototype.move = function(recommendation, toSave) {
|
||||||
* @param {Camera} camera Camera to move to
|
* @param {Camera} camera Camera to move to
|
||||||
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera
|
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera
|
||||||
*/
|
*/
|
||||||
L3D.PointerCamera.prototype.moveHermite = function(recommendation, toSave) {
|
L3D.PointerCamera.prototype.moveHermite = function(recommendation, toSave, recommendationId) {
|
||||||
if (toSave === undefined)
|
if (toSave === undefined)
|
||||||
toSave = true;
|
toSave = true;
|
||||||
|
|
||||||
var otherCamera = recommendation.camera || recommendation;
|
this.recommendationClicked = recommendationId;
|
||||||
|
|
||||||
this.recommendationClicked = otherCamera;
|
var otherCamera = recommendation.camera || recommendation;
|
||||||
|
|
||||||
this.moving = false;
|
this.moving = false;
|
||||||
this.movingHermite = true;
|
this.movingHermite = true;
|
||||||
|
@ -756,19 +756,22 @@ L3D.PointerCamera.prototype.redoable = function() {
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
L3D.PointerCamera.prototype.toList = function() {
|
L3D.PointerCamera.prototype.toList = function() {
|
||||||
this.updateMatrix();
|
|
||||||
this.updateMatrixWorld();
|
var camera = this; // (this.recommendationClicked === null ? this : this.cameras[this.recommendationClicked].camera);
|
||||||
|
|
||||||
|
camera.updateMatrix();
|
||||||
|
camera.updateMatrixWorld();
|
||||||
|
|
||||||
|
camera.matrixWorldInverse.getInverse(camera.matrixWorld);
|
||||||
|
|
||||||
var frustum = new THREE.Frustum();
|
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));
|
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
|
||||||
|
|
||||||
var ret =
|
var ret =
|
||||||
[[this.position.x, this.position.y, this.position.z],
|
[[camera.position.x, camera.position.y, camera.position.z],
|
||||||
[this.target.x, this.target.y, this.target.z],
|
[camera.target.x, camera.target.y, camera.target.z],
|
||||||
this.recommendationClicked !== null
|
this.recommendationClicked
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var i = 0; i < frustum.planes.length; i++) {
|
for (var i = 0; i < frustum.planes.length; i++) {
|
||||||
|
@ -782,5 +785,6 @@ L3D.PointerCamera.prototype.toList = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
|
||||||
self.isArrow = false;
|
self.isArrow = false;
|
||||||
if (typeof self.logReco === 'function') {
|
if (typeof self.logReco === 'function') {
|
||||||
var info = self.logReco(false, self.totalTime);
|
var info = self.logReco(false, self.totalTime);
|
||||||
require('fs').appendFileSync(info.path, info.value);
|
// require('fs').appendFileSync(info.path, info.value);
|
||||||
}
|
}
|
||||||
process.stderr.write('\033[31mArrowclicked finished !\033[0m\n');
|
process.stderr.write('\033[31mArrowclicked finished !\033[0m\n');
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
|
||||||
self.isArrow = true;
|
self.isArrow = true;
|
||||||
if (typeof self.logReco === 'function') {
|
if (typeof self.logReco === 'function') {
|
||||||
var info = self.logReco(true, self.totalTime);
|
var info = self.logReco(true, self.totalTime);
|
||||||
require('fs').appendFileSync(info.path, info.value);
|
// require('fs').appendFileSync(info.path, info.value);
|
||||||
}
|
}
|
||||||
process.stderr.write('\033[33mArrowclicked ! ' + JSON.stringify(self.cameras[self.event.id].camera.position) + '\033[0m\n');
|
process.stderr.write('\033[33mArrowclicked ! ' + JSON.stringify(self.cameras[self.event.id].camera.position) + '\033[0m\n');
|
||||||
if (self.quittingTime === Infinity)
|
if (self.quittingTime === Infinity)
|
||||||
|
|
|
@ -207,9 +207,9 @@ var ProgressiveLoader = function(path, scene, camera, callback, log, laggy, pref
|
||||||
// Only good for sponza model
|
// Only good for sponza model
|
||||||
this.camera._moveHermite = this.camera.moveHermite;
|
this.camera._moveHermite = this.camera.moveHermite;
|
||||||
|
|
||||||
this.camera.moveHermite = function(param) {
|
this.camera.moveHermite = function() {
|
||||||
var toSend = param.position.x > 0 ? 0 : 1;
|
console.log(arguments);
|
||||||
self.socket.emit('reco', toSend);
|
self.socket.emit('reco', arguments[2]);
|
||||||
self.camera._moveHermite.apply(self.camera, arguments);
|
self.camera._moveHermite.apply(self.camera, arguments);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ var ProgressiveLoader = function(path, scene, camera, callback, log, laggy, pref
|
||||||
|
|
||||||
this.mapFace = {};
|
this.mapFace = {};
|
||||||
|
|
||||||
this.prefetch = prefetch === undefined ? true : (!!prefetch);
|
this.prefetch = prefetch;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -434,11 +434,8 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||||
var param;
|
var param;
|
||||||
if (typeof self.onBeforeEmit === 'function') {
|
if (typeof self.onBeforeEmit === 'function') {
|
||||||
|
|
||||||
for (var m of self.meshes) {
|
|
||||||
m.geometry.computeBoundingSphere();
|
|
||||||
}
|
|
||||||
param = self.onBeforeEmit();
|
param = self.onBeforeEmit();
|
||||||
setTimeout(function() { self.socket.emit('next', self.getCamera(), param);}, 100);
|
self.socket.emit('next', self.getCamera(), param);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -467,6 +464,13 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ProgressiveLoader.prototype.computeBoundingSphere = function() {
|
||||||
|
for (var m of this.meshes) {
|
||||||
|
m.geometry.computeBoundingSphere();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the communication with the server
|
* Starts the communication with the server
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,7 +40,7 @@ L3D.ViewportRecommendation = function(arg1, arg2, arg3, arg4, position, target)
|
||||||
);
|
);
|
||||||
|
|
||||||
(function(self, direction, left, other) {
|
(function(self, direction, left, other) {
|
||||||
var material = new THREE.LineBasicMaterial({ color: '0x000000'});
|
var material = new THREE.LineBasicMaterial({ color: '0x000000', linewidth: 3});
|
||||||
var geometry = new THREE.Geometry();
|
var geometry = new THREE.Geometry();
|
||||||
var tmpDirection = L3D.Tools.mul(direction, -2);
|
var tmpDirection = L3D.Tools.mul(direction, -2);
|
||||||
var target = L3D.Tools.sum(self.camera.position, tmpDirection);
|
var target = L3D.Tools.sum(self.camera.position, tmpDirection);
|
||||||
|
|
|
@ -11,12 +11,12 @@ L3D.LogFunction = function(a,b) {
|
||||||
};
|
};
|
||||||
|
|
||||||
L3D.addLight = function(scene) {
|
L3D.addLight = function(scene) {
|
||||||
var directionalLight = new THREE.DirectionalLight(0xdddddd);
|
var directionalLight = new THREE.DirectionalLight(0x777777);
|
||||||
directionalLight.position.set(1, 2.5, 1).normalize();
|
directionalLight.position.set(1, 1, 0).normalize();
|
||||||
directionalLight.castShadow = false;
|
directionalLight.castShadow = false;
|
||||||
scene.add(directionalLight);
|
scene.add(directionalLight);
|
||||||
|
|
||||||
var ambientLight = new THREE.AmbientLight(0x555555);
|
var ambientLight = new THREE.AmbientLight(0xbbbbbb);
|
||||||
scene.add(ambientLight);
|
scene.add(ambientLight);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ L3D.createPeachRecommendations = function(width, height, rec) {
|
||||||
L3D.initBobombScene = function(scene, collidableObjects, recommendation, clickable) {
|
L3D.initBobombScene = function(scene, collidableObjects, recommendation, clickable) {
|
||||||
|
|
||||||
var loader = new L3D.ProgressiveLoader(
|
var loader = new L3D.ProgressiveLoader(
|
||||||
'/static/data/bobomb/bobomb battlefeild.obj',
|
'/static/data/bobomb/bobomb battlefeild_sub.obj',
|
||||||
scene,
|
scene,
|
||||||
recommendation,
|
recommendation,
|
||||||
function(object) {
|
function(object) {
|
||||||
|
@ -179,7 +179,9 @@ L3D.initBobombScene = function(scene, collidableObjects, recommendation, clickab
|
||||||
THREEx.Transparency.push(object);
|
THREEx.Transparency.push(object);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
L3D.LogFunction
|
L3D.LogFunction,
|
||||||
|
false,
|
||||||
|
prefetch
|
||||||
);
|
);
|
||||||
|
|
||||||
loader.load();
|
loader.load();
|
||||||
|
@ -200,6 +202,8 @@ L3D.resetBobombElements = function() {
|
||||||
|
|
||||||
L3D.generateCoins = function(totalCoins, coinIds) {
|
L3D.generateCoins = function(totalCoins, coinIds) {
|
||||||
|
|
||||||
|
return [];
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var tmp = [];
|
var tmp = [];
|
||||||
|
|
||||||
|
@ -354,7 +358,7 @@ L3D.initBobomb = function(camera, scene, coins, clickable, coinIds) {
|
||||||
L3D.initWhompScene = function(scene, collidableObjects, recommendation, clickable) {
|
L3D.initWhompScene = function(scene, collidableObjects, recommendation, clickable) {
|
||||||
|
|
||||||
var loader = new L3D.ProgressiveLoader(
|
var loader = new L3D.ProgressiveLoader(
|
||||||
'/static/data/whomp/Whomps Fortress.obj',
|
'/static/data/whomp/Whomps Fortress_sub.obj',
|
||||||
scene,
|
scene,
|
||||||
recommendation,
|
recommendation,
|
||||||
function(object) {
|
function(object) {
|
||||||
|
@ -375,7 +379,10 @@ L3D.initWhompScene = function(scene, collidableObjects, recommendation, clickabl
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
L3D.LogFunction
|
L3D.LogFunction,
|
||||||
|
false,
|
||||||
|
prefetch
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
loader.load();
|
loader.load();
|
||||||
|
@ -510,7 +517,7 @@ L3D.initWhomp = function(recommendation, scene, coins, clickable, coinIds) {
|
||||||
L3D.initMountainScene = function(scene, collidableObjects, recommendation, clickable) {
|
L3D.initMountainScene = function(scene, collidableObjects, recommendation, clickable) {
|
||||||
|
|
||||||
var loader = new L3D.ProgressiveLoader(
|
var loader = new L3D.ProgressiveLoader(
|
||||||
'/static/data/mountain/coocoolmountain.obj',
|
'/static/data/mountain/coocoolmountain_sub.obj',
|
||||||
scene,
|
scene,
|
||||||
recommendation,
|
recommendation,
|
||||||
function(object) {
|
function(object) {
|
||||||
|
@ -535,7 +542,10 @@ L3D.initMountainScene = function(scene, collidableObjects, recommendation, click
|
||||||
object.material.opacity = 0.5;
|
object.material.opacity = 0.5;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
L3D.LogFunction
|
L3D.LogFunction,
|
||||||
|
false,
|
||||||
|
prefetch
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
loader.load();
|
loader.load();
|
||||||
|
@ -670,26 +680,26 @@ L3D.initSponzaScene = function(scene, collidableObjects, recommendation, clickab
|
||||||
loader.load();
|
loader.load();
|
||||||
|
|
||||||
|
|
||||||
loader.getCamera = function() {
|
// loader.getCamera = function() {
|
||||||
var ret = loader.camera.toList();
|
// var ret = loader.camera.toList();
|
||||||
ret[0][0] *= 10;
|
// ret[0][0] *= 10;
|
||||||
ret[0][1] *= 10;
|
// ret[0][1] *= 10;
|
||||||
ret[0][2] *= 10;
|
// ret[0][2] *= 10;
|
||||||
|
|
||||||
ret[1][0] *= 10;
|
// ret[1][0] *= 10;
|
||||||
ret[1][1] *= 10;
|
// ret[1][1] *= 10;
|
||||||
ret[1][2] *= 10;
|
// ret[1][2] *= 10;
|
||||||
|
|
||||||
// Planes
|
// // Planes
|
||||||
for (var i = 2; i < ret.length; i++) {
|
// for (var i = 3; i < ret.length; i++) {
|
||||||
|
|
||||||
ret[i][3] *= 10;
|
// ret[i][3] *= 10;
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
return ret;
|
// return ret;
|
||||||
};
|
// };
|
||||||
loader.obj.scale.set(0.1,0.1,0.1);
|
// loader.obj.scale.set(0.1,0.1,0.1);
|
||||||
|
|
||||||
collidableObjects.push(loader.obj);
|
collidableObjects.push(loader.obj);
|
||||||
loader.obj.raycastable = true;
|
loader.obj.raycastable = true;
|
||||||
|
@ -724,6 +734,38 @@ L3D.createSponzaRecommendations = function(width, height) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
// createRecommendation(
|
||||||
|
// new THREE.Vector3(-2.591997650227227,4.652225309342689,-2.815524195264902),
|
||||||
|
// new THREE.Vector3(-40.87987891143996,10.202406707437795,7.344871219063935)
|
||||||
|
// )
|
||||||
|
// ,createRecommendation(
|
||||||
|
// new THREE.Vector3(-20.507451191489245,1.7638914167988349,1.9557104822169127),
|
||||||
|
// new THREE.Vector3(-58.90750279083062,7.314072814893941,-7.772163058087716)
|
||||||
|
// )
|
||||||
|
// ,
|
||||||
|
// createRecommendation(
|
||||||
|
// new THREE.Vector3(-23.383482289183434,14.264152490508069,-1.2119079930928534),
|
||||||
|
// new THREE.Vector3(-1.7847952083517313,1.9364343472313017,30.117376738037517)
|
||||||
|
// ),
|
||||||
|
// createRecommendation(
|
||||||
|
// new THREE.Vector3(2.327317420088316,0.3629147522258326,-0.3325792884643282),
|
||||||
|
// new THREE.Vector3(1.3934131694970663,-0.8288981685786133,3.369771966148228)
|
||||||
|
// ),
|
||||||
|
// createRecommendation(
|
||||||
|
// new THREE.Vector3(22.983553977938616,3.829033470023654,0.7135547783419287),
|
||||||
|
// new THREE.Vector3(1.9041126108599506,-8.375131998286331,32.4423350397072)
|
||||||
|
// )
|
||||||
|
// createRecommendation(
|
||||||
|
// new THREE.Vector3(-12.939581055355553,3.796374966524073,-2.463006239142574),
|
||||||
|
// new THREE.Vector3(-51.61901925503118,-1.1193807374029414,6.466518183623911)
|
||||||
|
// )
|
||||||
|
createRecommendation(
|
||||||
|
new THREE.Vector3(1.3571661176961554,4.934280286310308,-4.294700794239404),
|
||||||
|
new THREE.Vector3(-31.49512083496389,15.286798072464663,16.04129235749628)
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
createRecommendation(
|
createRecommendation(
|
||||||
new THREE.Vector3(97.36225946503932,10.925697484337014,12.852363038244272),
|
new THREE.Vector3(97.36225946503932,10.925697484337014,12.852363038244272),
|
||||||
|
@ -742,8 +784,8 @@ L3D.createSponzaCoins = function() {
|
||||||
|
|
||||||
L3D.resetSponzaElements = function() {
|
L3D.resetSponzaElements = function() {
|
||||||
return {
|
return {
|
||||||
position: new THREE.Vector3(92.98373669520107,60.8877777990862,11.130138641670737),
|
position: new THREE.Vector3(9.298373669520107,6.08877777990862,1.1130138641670737),
|
||||||
target: new THREE.Vector3(53.76696417668598,56.09739213575453,4.877382575136091)
|
target: new THREE.Vector3(5.376696417668598,5.609739213575453,0.4877382575136091)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -757,7 +799,7 @@ L3D.initSponza = function(recommendation, scene, coins, clickable) {
|
||||||
recommendation.resetElements = L3D.resetSponzaElements();
|
recommendation.resetElements = L3D.resetSponzaElements();
|
||||||
recommendation.collidableObjects = collidableObjects;
|
recommendation.collidableObjects = collidableObjects;
|
||||||
|
|
||||||
recommendation.speed = 0.05;
|
recommendation.speed = 0.005;
|
||||||
recommendation.reset();
|
recommendation.reset();
|
||||||
recommendation.save();
|
recommendation.save();
|
||||||
|
|
||||||
|
|
|
@ -317,6 +317,19 @@ var availableMeshNames = {
|
||||||
|
|
||||||
'/static/data/sponza/sponza.obj': {
|
'/static/data/sponza/sponza.obj': {
|
||||||
done: false,
|
done: false,
|
||||||
|
transfo : {
|
||||||
|
rotation: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
translation: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
},
|
||||||
|
scale: 0.02
|
||||||
|
},
|
||||||
recommendations : L3D.createSponzaRecommendations(1134,768)
|
recommendations : L3D.createSponzaRecommendations(1134,768)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,6 +359,8 @@ function pushMesh(name) {
|
||||||
|
|
||||||
var reco = availableMeshNames[name].recommendations[i].camera;
|
var reco = availableMeshNames[name].recommendations[i].camera;
|
||||||
|
|
||||||
|
reco.aspect = 1134 / 768;
|
||||||
|
|
||||||
reco.lookAt(reco.target);
|
reco.lookAt(reco.target);
|
||||||
|
|
||||||
reco.updateMatrix();
|
reco.updateMatrix();
|
||||||
|
|
|
@ -11,7 +11,7 @@ function readIt(sceneNumber, recoId) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
numberOfReco = [0, 0, 12, 12, 11];
|
numberOfReco = [0, 0, 12, 12, 11, 2];
|
||||||
|
|
||||||
function readAll(sceneNumber) {
|
function readAll(sceneNumber) {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
|
@ -30,15 +30,15 @@ try
|
||||||
JSON.parse(fs.readFileSync('./geo/mat1.json')),
|
JSON.parse(fs.readFileSync('./geo/mat1.json')),
|
||||||
JSON.parse(fs.readFileSync('./geo/mat2.json')),
|
JSON.parse(fs.readFileSync('./geo/mat2.json')),
|
||||||
JSON.parse(fs.readFileSync('./geo/mat3.json')),
|
JSON.parse(fs.readFileSync('./geo/mat3.json')),
|
||||||
[[1,1,0],
|
[[1,1],
|
||||||
[1,2,0],
|
[1,2]]
|
||||||
[2,1,0]]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
var facesToSend = [
|
var facesToSend = [
|
||||||
readAll(2),
|
readAll(2),
|
||||||
readAll(3),
|
readAll(3),
|
||||||
readAll(4)
|
readAll(4),
|
||||||
|
readAll(5)
|
||||||
];
|
];
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -188,9 +188,9 @@ geo.MeshStreamer = function(path) {
|
||||||
this.maxThreshold = 0.85;
|
this.maxThreshold = 0.85;
|
||||||
this.currentlyPrefetching = false;
|
this.currentlyPrefetching = false;
|
||||||
|
|
||||||
this.begining = true;
|
this.beginning = false;
|
||||||
|
|
||||||
this.beginingThreshold = 0.9;
|
this.beginningThreshold = 0.9;
|
||||||
|
|
||||||
this.frustumPercentage = 0.6;
|
this.frustumPercentage = 0.6;
|
||||||
this.prefetchPercentage = 1 - this.frustumPercentage;
|
this.prefetchPercentage = 1 - this.frustumPercentage;
|
||||||
|
@ -199,6 +199,7 @@ geo.MeshStreamer = function(path) {
|
||||||
* Number of element to send by packet
|
* Number of element to send by packet
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
|
// this.chunk = 100000;
|
||||||
this.chunk = 1250;
|
this.chunk = 1250;
|
||||||
|
|
||||||
this.previousReco = 0;
|
this.previousReco = 0;
|
||||||
|
@ -347,6 +348,10 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
||||||
self.predictionTable = predictionTables[2];
|
self.predictionTable = predictionTables[2];
|
||||||
self.facesToSend = facesToSend[2];
|
self.facesToSend = facesToSend[2];
|
||||||
break;
|
break;
|
||||||
|
case '/static/data/sponza/sponza.obj':
|
||||||
|
self.predictionTable = predictionTables[3];
|
||||||
|
self.facesToSend = facesToSend[3];
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
self.predictionTable = predictionTables[3];
|
self.predictionTable = predictionTables[3];
|
||||||
};
|
};
|
||||||
|
@ -390,7 +395,8 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
||||||
socket.on('next', function(_camera) { // score) {
|
socket.on('next', function(_camera) { // score) {
|
||||||
|
|
||||||
var cameraFrustum = {};
|
var cameraFrustum = {};
|
||||||
var begining = self.begining;
|
var beginning = self.beginning;
|
||||||
|
var cameraExists = false;
|
||||||
|
|
||||||
// Clean camera attribute
|
// Clean camera attribute
|
||||||
if (_camera !== null) {
|
if (_camera !== null) {
|
||||||
|
@ -424,87 +430,34 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cameraExists = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create config for proportions of chunks
|
// Create config for proportions of chunks
|
||||||
var config;
|
var config;
|
||||||
var didPrefetch = false;
|
var didPrefetch = false;
|
||||||
|
|
||||||
if (self.begining === true) {
|
// if (false) {
|
||||||
|
|
||||||
console.log('Begining : full init');
|
if (cameraExists) {
|
||||||
config = [{recommendationId : 0, proportion:1, smart: true}];
|
|
||||||
|
|
||||||
} else if (!self.prefetch) {
|
switch (self.prefetch) {
|
||||||
// Case without prefetch
|
case 'V-PP':
|
||||||
console.log("No prefetching");
|
config = self.generateConfig_V_PP(cameraFrustum, recommendationClicked);
|
||||||
config = [{ frustum: cameraFrustum, proportion: 1}];
|
break;
|
||||||
|
case 'V-PD':
|
||||||
} else if (recommendationClicked !== null) {
|
config = self.generateConfig_V_PD(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
// Case full reco
|
case 'V-PP+PD':
|
||||||
console.log("Going to " + recommendationClicked);
|
config = self.generateConfig_V_PP_PD(cameraFrustum, recommendationClicked);
|
||||||
console.log("Recommendation is clicking : full for " + JSON.stringify(self.mesh.recommendations[recommendationClicked].position));
|
break;
|
||||||
// config = [{frustum: cameraFrustum, proportion:0.5}, {frustum : self.mesh.recommendations[recommendationClicked], proportion: 0.5}];
|
case 'NV-PN':
|
||||||
config = [{recommendationId : recommendationClicked + 1, proportion: 1, smart:true}];
|
default:
|
||||||
|
config = self.generateConfig_NV_PN(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
// } else if (score < self.minThreshold || (!self.currentlyPrefetching && score < self.maxThreshold)) {
|
// console.log(self.prefetch)
|
||||||
|
// process.exit(-1);
|
||||||
// // Case no prefetch
|
|
||||||
// console.log("Not good % (" + score + ", prefetch = " + self.currentlyPrefetching + "), full frustum");
|
|
||||||
// config = [{ frustum: cameraFrustum, proportion: 1}];
|
|
||||||
|
|
||||||
// if (score < self.minThreshold)
|
|
||||||
// self.currentlyPrefetching = false;
|
|
||||||
|
|
||||||
} else { // if (score > self.maxThreshold || (self.currentlyPrefetching && score > self.minThreshold) {
|
|
||||||
|
|
||||||
// Case full prefetch
|
|
||||||
console.log("Allow some prefetching");
|
|
||||||
|
|
||||||
didPrefetch = true;
|
|
||||||
config = [{ frustum: cameraFrustum, proportion : self.frustumPercentage}];
|
|
||||||
|
|
||||||
// Find best recommendation
|
|
||||||
var bestReco;
|
|
||||||
var bestScore = -Infinity;
|
|
||||||
var bestIndex = null;
|
|
||||||
|
|
||||||
if (self.predictionTable !== undefined) {
|
|
||||||
|
|
||||||
var sum = 0;
|
|
||||||
|
|
||||||
for (var i = 1; i <= self.mesh.recommendations.length; i++) {
|
|
||||||
|
|
||||||
sum += self.predictionTable[self.previousReco][i];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 1; i <= self.mesh.recommendations.length; i++) {
|
|
||||||
|
|
||||||
if (self.predictionTable[self.previousReco][i] > 0) {
|
|
||||||
|
|
||||||
config.push({
|
|
||||||
|
|
||||||
proportion : self.predictionTable[self.previousReco][i] * self.prefetchPercentage / sum,
|
|
||||||
recommendationId : i,
|
|
||||||
smart: true
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (score > self.maxThreshold)
|
|
||||||
// self.currentlyPrefetching = true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
process.stderr.write('ERROR : PREDICTION TABLE IF UNDEFINED');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,123 +473,83 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
console.log(next.configSizes);
|
if (self.beginning === true && next.size < self.chunk) {
|
||||||
|
self.beginning = false;
|
||||||
|
|
||||||
// console.log('Time to generate chunk : ' + (Date.now() - oldTime) + 'ms');
|
switch (self.prefetch) {
|
||||||
|
case 'V-PP':
|
||||||
|
config = self.generateConfig_V_PP(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
case 'V-PD':
|
||||||
|
config = self.generateConfig_V_PD(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
case 'V-PP+PD':
|
||||||
|
config = self.generateConfig_V_PP_PD(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
case 'NV-PN':
|
||||||
|
default:
|
||||||
|
config = self.generateConfig_NV_PN(cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (self.prefetch && next.size < self.chunk) {
|
var fillElements = self.nextElements(config, self.chunk - next.size);
|
||||||
|
|
||||||
console.log("Chunk not full : prefetch reco");
|
next.configSizes = fillElements.configSizes;
|
||||||
|
next.data.push.apply(next.data, fillElements.data);
|
||||||
|
next.size += fillElements.size;
|
||||||
|
}
|
||||||
|
|
||||||
// Recompute config
|
|
||||||
var newConfig = [];
|
|
||||||
var sum = 0;
|
|
||||||
|
|
||||||
if (!didPrefetch) {
|
// Chunk is not empty, compute fill config
|
||||||
|
if (next.size < self.chunk) {
|
||||||
|
|
||||||
if (self.predictionTable !== undefined) {
|
switch (self.prefetch) {
|
||||||
|
case 'V-PP':
|
||||||
var sum = 0;
|
config = self.generateFillConfig_V_PP(config, next, cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
for (var i = 1; i <= self.mesh.recommendations.length; i++) {
|
case 'V-PD':
|
||||||
|
config = self.generateFillConfig_V_PD(config, next, cameraFrustum, recommendationClicked);
|
||||||
sum += self.predictionTable[self.previousReco][i];
|
break;
|
||||||
|
case 'V-PP+PD':
|
||||||
|
config = self.generateFillConfig_V_PP_PD(config, next, cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
case 'NV-PN':
|
||||||
|
default:
|
||||||
|
config = self.generateFillConfig_NV_PN(config, next, cameraFrustum, recommendationClicked);
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 1; i <= self.mesh.recommendations.length; i++) {
|
|
||||||
|
|
||||||
if (self.predictionTable[self.previousReco][i] > 0) {
|
fillElements = self.nextElements(config, self.chunk - next.size);
|
||||||
|
|
||||||
newConfig.push({
|
next.data.push.apply(next.data, fillElements.data);
|
||||||
|
next.size += fillElements.size;
|
||||||
proportion : self.predictionTable[self.previousReco][i] / (sum),
|
|
||||||
recommendationId : i,
|
|
||||||
smart : true
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
for (var i = 0; i < config.length; i++) {
|
next = { data : [], size : 0 };
|
||||||
|
|
||||||
// Check if config was full
|
|
||||||
if (next.configSizes[i] >= self.chunk * config[i].proportion) {
|
|
||||||
|
|
||||||
newConfig.push(config[i]);
|
|
||||||
sum += config[i].proportion;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normalize config probabilities
|
|
||||||
for (var i = 0; i < newConfig.length; i++) {
|
|
||||||
|
|
||||||
newConfig[i].proportion /= sum;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var newData = self.nextElements(newConfig, self.chunk - next.size);
|
|
||||||
|
|
||||||
next.data.push.apply(next.data, newData.data);
|
|
||||||
|
|
||||||
// console.log(
|
|
||||||
// 'Adding ' +
|
|
||||||
// newData.size +
|
|
||||||
// ' for newConfig : '
|
|
||||||
// + JSON.stringify(newConfig.map(function(o) { return o.proportion}))
|
|
||||||
// );
|
|
||||||
|
|
||||||
next.size = next.size + newData.size;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (begining && !self.prefetch && next.size < self.chunk) {
|
|
||||||
|
|
||||||
console.log("Chunk not full (begining) : fill frustum");
|
|
||||||
|
|
||||||
// If nothing, just serve stuff
|
|
||||||
var tmp = self.nextElements([
|
|
||||||
{
|
|
||||||
proportion: 1,
|
|
||||||
frustum: cameraFrustum
|
|
||||||
}
|
|
||||||
], self.chunk - next.size);
|
|
||||||
|
|
||||||
next.data.push.apply(next.data, tmp.data);
|
|
||||||
next.size += tmp.size;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If still not empty, fill linear
|
||||||
if (next.size < self.chunk) {
|
if (next.size < self.chunk) {
|
||||||
|
|
||||||
console.log("Chunk not full : fill linear");
|
fillElements = self.nextElements([], self.chunk - next.size);
|
||||||
|
|
||||||
// If nothing, just serve stuff
|
next.data.push.apply(next.data, fillElements.data);
|
||||||
var tmp = self.nextElements([
|
next.size += fillElements.size;
|
||||||
// {
|
|
||||||
// proportion: 1,
|
|
||||||
// frustum: cameraFrustum
|
|
||||||
// }
|
|
||||||
], self.chunk - next.size);
|
|
||||||
|
|
||||||
next.data.push.apply(next.data, tmp.data);
|
|
||||||
next.size += tmp.size;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var config = [{proportion: 1, smart: true, recommendationId: 1}];
|
||||||
|
// var next = self.nextElements(config);
|
||||||
|
|
||||||
console.log('Chunk of size ' + next.size + ' (generated in ' + (Date.now() - oldTime) + 'ms)');
|
console.log('Chunk of size ' + next.size + ' (generated in ' + (Date.now() - oldTime) + 'ms)');
|
||||||
// console.log('Time to generate chunk : ' + (Date.now() - oldTime) + 'ms');
|
|
||||||
|
|
||||||
if (next.data.length === 0) {
|
if (next.data.length === 0) {
|
||||||
|
|
||||||
|
@ -682,6 +595,236 @@ geo.MeshStreamer.prototype.nextMaterials = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateConfig_NV_PN = function(cameraFrustum) {
|
||||||
|
|
||||||
|
var config;
|
||||||
|
|
||||||
|
// if (this.beginning === true) {
|
||||||
|
|
||||||
|
// console.log('Begining : full init');
|
||||||
|
// config = [{recommendationId : 0, proportion:1, smart: true}];
|
||||||
|
|
||||||
|
|
||||||
|
// } else {
|
||||||
|
|
||||||
|
// Case without prefetch
|
||||||
|
console.log("No prefetching");
|
||||||
|
config = [{ frustum: cameraFrustum, proportion: 1}];
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateConfig_V_PD = function(cameraFrustum, recommendationClicked) {
|
||||||
|
|
||||||
|
var config;
|
||||||
|
if (recommendationClicked != null) {
|
||||||
|
|
||||||
|
if (this.beginning === true) {
|
||||||
|
this.beginning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case full reco
|
||||||
|
console.log("Going to " + recommendationClicked);
|
||||||
|
console.log("Recommendation is clicking : full for " + JSON.stringify(this.mesh.recommendations[recommendationClicked].position));
|
||||||
|
config = [{recommendationId : recommendationClicked + 1, proportion: 1, smart:true}];
|
||||||
|
|
||||||
|
} else if (this.beginning === true) {
|
||||||
|
|
||||||
|
console.log('Begining : full init');
|
||||||
|
config = [{recommendationId : 0, proportion:1, smart: true}];
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Case without prefetch
|
||||||
|
console.log("No prefetching");
|
||||||
|
config = [{ frustum: cameraFrustum, proportion: 1}];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateConfig_V_PP = function(cameraFrustum) {
|
||||||
|
|
||||||
|
var config;
|
||||||
|
|
||||||
|
if (this.beginning === true) {
|
||||||
|
|
||||||
|
console.log('Begining : full init');
|
||||||
|
config = [{recommendationId : 0, proportion:1, smart: true}];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Case full prefetch
|
||||||
|
console.log("Allow some prefetching");
|
||||||
|
|
||||||
|
didPrefetch = true;
|
||||||
|
config = [{ frustum: cameraFrustum, proportion : this.frustumPercentage}];
|
||||||
|
|
||||||
|
if (this.predictionTable !== undefined) {
|
||||||
|
|
||||||
|
var sum = 0;
|
||||||
|
|
||||||
|
for (var i = 1; i <= this.mesh.recommendations.length; i++) {
|
||||||
|
|
||||||
|
sum += this.predictionTable[this.previousReco][i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 1; i <= this.mesh.recommendations.length; i++) {
|
||||||
|
|
||||||
|
if (this.predictionTable[this.previousReco][i] > 0) {
|
||||||
|
|
||||||
|
config.push({
|
||||||
|
|
||||||
|
proportion : this.predictionTable[this.previousReco][i] * this.prefetchPercentage / sum,
|
||||||
|
recommendationId : i,
|
||||||
|
smart: true
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
process.stderr.write('ERROR : PREDICTION TABLE IF UNDEFINED');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateConfig_V_PP_PD = function(cameraFrustum, recommendationClicked) {
|
||||||
|
|
||||||
|
var config;
|
||||||
|
|
||||||
|
if (recommendationClicked != null) {
|
||||||
|
|
||||||
|
if (this.beginning === true) {
|
||||||
|
this.beginning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case full reco
|
||||||
|
console.log("Going to " + recommendationClicked);
|
||||||
|
console.log("Recommendation is clicking : full for " + JSON.stringify(this.mesh.recommendations[recommendationClicked].position));
|
||||||
|
config = [{recommendationId : recommendationClicked + 1, proportion: 1, smart:true}];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} else if (this.beginning === true) {
|
||||||
|
|
||||||
|
console.log('Begining : full init');
|
||||||
|
config = [{recommendationId : 0, proportion:1, smart: true}];
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Case full prefetch
|
||||||
|
console.log("Allow some prefetching");
|
||||||
|
|
||||||
|
config = [{ frustum: cameraFrustum, proportion : this.frustumPercentage}];
|
||||||
|
|
||||||
|
// Find best recommendation
|
||||||
|
var bestReco;
|
||||||
|
var bestScore = -Infinity;
|
||||||
|
var bestIndex = null;
|
||||||
|
|
||||||
|
if (this.predictionTable !== undefined) {
|
||||||
|
|
||||||
|
var sum = 0;
|
||||||
|
|
||||||
|
for (var i = 1; i <= this.mesh.recommendations.length; i++) {
|
||||||
|
|
||||||
|
sum += this.predictionTable[this.previousReco][i];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 1; i <= this.mesh.recommendations.length; i++) {
|
||||||
|
|
||||||
|
if (this.predictionTable[this.previousReco][i] > 0) {
|
||||||
|
|
||||||
|
config.push({
|
||||||
|
|
||||||
|
proportion : this.predictionTable[this.previousReco][i] * this.prefetchPercentage / sum,
|
||||||
|
recommendationId : i,
|
||||||
|
smart: true
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (score > this.maxThreshold)
|
||||||
|
// this.currentlyPrefetching = true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
process.stderr.write('ERROR : PREDICTION TABLE IF UNDEFINED');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateFillConfig_NV_PN =
|
||||||
|
function(previousConfig, previousResult, cameraFrustum, recommendationClicked) {
|
||||||
|
|
||||||
|
// Nothing to do better than linear, let default fill do its work
|
||||||
|
return {data:[], size: 0};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateFillConfig_V_PP =
|
||||||
|
function(previousConfig, previousResult, cameraFrustum, recommendationClicked) {
|
||||||
|
|
||||||
|
var sum = 0;
|
||||||
|
var newConfig = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < previousConfig.length; i++) {
|
||||||
|
|
||||||
|
// Check if previousConfig was full
|
||||||
|
if (previousResult.configSizes[i] >= this.chunk * previousConfig[i].proportion) {
|
||||||
|
|
||||||
|
newConfig.push(previousConfig[i]);
|
||||||
|
sum += previousConfig[i].proportion;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize previousConfig probabilities
|
||||||
|
for (var i = 0; i < newConfig.length; i++) {
|
||||||
|
|
||||||
|
newConfig[i].proportion /= sum;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return newConfig;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateFillConfig_V_PP_PD =
|
||||||
|
geo.MeshStreamer.prototype.generateFillConfig_V_PP;
|
||||||
|
|
||||||
|
geo.MeshStreamer.prototype.generateFillConfig_V_PD =
|
||||||
|
function(previousConfig, previousResult, cameraFrustum, recommendationClicked) {
|
||||||
|
|
||||||
|
return [{proportion:1, frustum: cameraFrustum}];
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the next elements
|
* Prepare the next elements
|
||||||
* @param {camera} _camera a camera that can be usefull to do smart streaming (stream
|
* @param {camera} _camera a camera that can be usefull to do smart streaming (stream
|
||||||
|
@ -781,6 +924,10 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
||||||
|
|
||||||
area += faceInfo.area;
|
area += faceInfo.area;
|
||||||
|
|
||||||
|
// if (area > 0.6) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
if (this.faces[faceInfo.index] !== true) {
|
if (this.faces[faceInfo.index] !== true) {
|
||||||
|
|
||||||
var face = this.mesh.faces[faceInfo.index];
|
var face = this.mesh.faces[faceInfo.index];
|
||||||
|
@ -788,31 +935,24 @@ geo.MeshStreamer.prototype.nextElements = function(config, chunk) {
|
||||||
if (face === undefined) {
|
if (face === undefined) {
|
||||||
console.log(faceInfo.index, this.mesh.faces.length);
|
console.log(faceInfo.index, this.mesh.faces.length);
|
||||||
console.log('ERROR !!!');
|
console.log('ERROR !!!');
|
||||||
|
} else {
|
||||||
|
buffers[configIndex].push(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffers[configIndex].push(face);
|
} else if (this.beginning === true) {
|
||||||
|
|
||||||
} else if (this.begining === true) {
|
|
||||||
|
|
||||||
currentArea += faceInfo.area;
|
currentArea += faceInfo.area;
|
||||||
|
|
||||||
if (currentArea > this.beginingThreshold) {
|
if (currentArea > this.beginningThreshold) {
|
||||||
|
|
||||||
this.begining = false;
|
this.beginning = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (area > 0.9) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalSize = 0;
|
var totalSize = 0;
|
||||||
|
|
|
@ -66,6 +66,13 @@ Log.dberror = function(error) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Log.prefetcherror = function(error) {
|
||||||
|
log(
|
||||||
|
'[PFE] ' + new Date() + ' ' + error,
|
||||||
|
Colors.RED
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
Log.mailerror = function(error) {
|
Log.mailerror = function(error) {
|
||||||
log(
|
log(
|
||||||
'[MLE] ' + new Date() + ' ' + error,
|
'[MLE] ' + new Date() + ' ' + error,
|
||||||
|
|
|
@ -83,9 +83,12 @@ module.exports.loadFromFile = loadFromFile;
|
||||||
function main() {
|
function main() {
|
||||||
|
|
||||||
let loader = new L3D.ProgressiveLoader(
|
let loader = new L3D.ProgressiveLoader(
|
||||||
'/static/data/castle/princess peaches castle (outside).obj',
|
// '/static/data/castle/princess peaches castle (outside).obj',
|
||||||
|
'/static/data/sponza/sponza.obj',
|
||||||
new THREE.Object3D(),
|
new THREE.Object3D(),
|
||||||
null
|
null,
|
||||||
|
undefined,
|
||||||
|
function(a,b) { console.log(100*a/b + '%'); }
|
||||||
);
|
);
|
||||||
|
|
||||||
loader.load(function() {
|
loader.load(function() {
|
||||||
|
|
114
server/server.js
114
server/server.js
|
@ -1,41 +1,43 @@
|
||||||
var http = require('http');
|
function main() {
|
||||||
var express = require('express');
|
|
||||||
var jade = require('jade');
|
|
||||||
var pg = require('pg');
|
|
||||||
|
|
||||||
var favicon = require('serve-favicon');
|
var http = require('http');
|
||||||
|
var express = require('express');
|
||||||
|
var jade = require('jade');
|
||||||
|
var pg = require('pg');
|
||||||
|
|
||||||
// secret variables
|
var favicon = require('serve-favicon');
|
||||||
var secret = require('./private');
|
|
||||||
|
|
||||||
var app = express();
|
// secret variables
|
||||||
|
var secret = require('./private');
|
||||||
|
|
||||||
// Socket.io initialization
|
var app = express();
|
||||||
var http = require('http').Server(app);
|
|
||||||
var io = require('socket.io')(http);
|
|
||||||
require('./socket.js')(io);
|
|
||||||
|
|
||||||
var bodyParser = require('body-parser');
|
// Socket.io initialization
|
||||||
var session = require('cookie-session');
|
var http = require('http').Server(app);
|
||||||
var cookieParser = require('cookie-parser');
|
var io = require('socket.io')(http);
|
||||||
var urls = require('./urls');
|
require('./socket.js')(io);
|
||||||
var Log = require('./lib/NodeLog.js');
|
|
||||||
|
|
||||||
var isDev = app.get('env') === 'development';
|
var bodyParser = require('body-parser');
|
||||||
|
var session = require('cookie-session');
|
||||||
|
var cookieParser = require('cookie-parser');
|
||||||
|
var urls = require('./urls');
|
||||||
|
var Log = require('./lib/NodeLog.js');
|
||||||
|
|
||||||
app.set('view engine', 'jade');
|
var isDev = app.get('env') === 'development';
|
||||||
app.set('trust proxy', 1);
|
|
||||||
|
|
||||||
app.use(cookieParser(secret.secret));
|
app.set('view engine', 'jade');
|
||||||
app.use(session({
|
app.set('trust proxy', 1);
|
||||||
|
|
||||||
|
app.use(cookieParser(secret.secret));
|
||||||
|
app.use(session({
|
||||||
keys: [secret.secret]
|
keys: [secret.secret]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.use(bodyParser.text());
|
app.use(bodyParser.text());
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
|
||||||
var start = Date.now();
|
var start = Date.now();
|
||||||
|
|
||||||
|
@ -49,11 +51,11 @@ app.use(function(req, res, next) {
|
||||||
res.locals.urls = urls;
|
res.locals.urls = urls;
|
||||||
res.locals.session = req.session;
|
res.locals.session = req.session;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set a cookie to know if already came. If not, France laws force to
|
// Set a cookie to know if already came. If not, France laws force to
|
||||||
// warn the user that the website uses cookies.
|
// warn the user that the website uses cookies.
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
if (req.cookies.alreadyCame) {
|
if (req.cookies.alreadyCame) {
|
||||||
res.locals.alertCookie = false;
|
res.locals.alertCookie = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,22 +68,22 @@ app.use(function(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load controllers
|
// Load controllers
|
||||||
require('./lib/controllers')(app);
|
require('./lib/controllers')(app);
|
||||||
|
|
||||||
// Load post to log data from user study
|
// Load post to log data from user study
|
||||||
require('./lib/posts')(app);
|
require('./lib/posts')(app);
|
||||||
|
|
||||||
// Static files
|
// Static files
|
||||||
app.use('/static', express.static('../static'));
|
app.use('/static', express.static('../static'));
|
||||||
|
|
||||||
// Favicon
|
// Favicon
|
||||||
app.use(favicon(__dirname + '/../static/ico/favicon.ico'));
|
app.use(favicon(__dirname + '/../static/ico/favicon.ico'));
|
||||||
|
|
||||||
// When error raised
|
// When error raised
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res, next) {
|
||||||
if (err.status === 404) {
|
if (err.status === 404) {
|
||||||
res.setHeader('Content-Type', 'text/html');
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
|
||||||
|
@ -89,30 +91,34 @@ app.use(function(err, req, res, next) {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// When route not found, raise not found
|
// When route not found, raise not found
|
||||||
app.use(function(req, res) {
|
app.use(function(req, res) {
|
||||||
res.setHeader('Content-Type', 'text/html');
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
|
||||||
res.render('404.jade', res.locals, function(err, result) {
|
res.render('404.jade', res.locals, function(err, result) {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set ports and ip address
|
// Set ports and ip address
|
||||||
var serverPort, serverIpAddress;
|
var serverPort, serverIpAddress;
|
||||||
if ( isDev ) {
|
if ( isDev ) {
|
||||||
serverPort = 4000;
|
serverPort = 4000;
|
||||||
// serverIpAddress = require('ip').address();
|
// serverIpAddress = require('ip').address();
|
||||||
serverIpAddress = '0.0.0.0';
|
serverIpAddress = '0.0.0.0';
|
||||||
} else {
|
} else {
|
||||||
// Openhift conf
|
// Openhift conf
|
||||||
serverPort = process.env.OPENSHIFT_NODEJS_PORT || 8080;
|
serverPort = process.env.OPENSHIFT_NODEJS_PORT || 8080;
|
||||||
serverIpAddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
|
serverIpAddress = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start server
|
||||||
|
http.listen(serverPort, serverIpAddress, function() {
|
||||||
|
Log.ready("Now listening " + serverIpAddress + ":" + serverPort);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start server
|
module.exports = main;
|
||||||
http.listen(serverPort, serverIpAddress, function() {
|
|
||||||
Log.ready("Now listening " + serverIpAddress + ":" + serverPort);
|
|
||||||
});
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
type="RELEASE"
|
type="RELEASE"
|
||||||
|
|
||||||
if [ "$1" == "--dev" ] || [ "$1" == "-d" ]; then
|
if [ "$1" == "--dev" ] || [ "$1" == "-d" ]; then
|
||||||
echo yes
|
|
||||||
type="DEV"
|
type="DEV"
|
||||||
elif [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
elif [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
|
||||||
echo -e "This is the 3dinterface builder"
|
echo -e "This is the 3dinterface builder"
|
||||||
|
|
Loading…
Reference in New Issue