Monster commit

- New analysis functions
- Scene rotation and scale done server side
- PGSQL files are now launchable
- New sql queries
- Removed dependancy from ip
This commit is contained in:
Thomas FORGIONE
2015-10-20 16:30:52 +02:00
parent 58f6caca40
commit e5eacddc58
16 changed files with 782 additions and 43 deletions

View File

@@ -1,12 +1,72 @@
var Log = require('../lib/NodeLog.js');
function clone(vec) {
return {x : vec.x, y : vec.y, z : vec.z};
}
function rotation(vec1, x, y, z) {
var cos = Math.cos(z);
var sin = Math.sin(z);
var newVec = {x:0, y:0, z:0};
oldVec = clone(vec1);
newVec.x = cos * oldVec.x - sin * oldVec.y;
newVec.y = sin * oldVec.x + cos * oldVec.y;
newVec.z = oldVec.z;
oldVec = clone(newVec);
cos = Math.cos(y);
sin = Math.sin(y);
newVec.x = cos * oldVec.x + sin * oldVec.z;
newVec.y = oldVec.y;
newVec.z = - sin * oldVec.x + cos * oldVec.z;
cos = Math.cos(x);
sin = Math.sin(x);
oldVec = clone(newVec);
newVec.x = oldVec.x;
newVec.y = oldVec.y * cos - oldVec.z * sin;
newVec.z = oldVec.y * sin + oldVec.z * cos;
return clone(newVec);
}
function applyTransformation(vector, transfo) {
var ret = rotation(vector, transfo.rotation.x, transfo.rotation.y, transfo.rotation.z);
var scale = transfo.scale || 1;
return {
x: (ret.x + transfo.translation.x) * scale,
y: (ret.y + transfo.translation.y) * scale,
z: (ret.z + transfo.translation.z) * scale
};
}
/**
* Represents a mesh. All meshes are loaded once in geo.availableMesh to avoid
* loading at each mesh request
* @constructor
* @memberOf geo
*/
geo.MeshContainer = function(path, callback) {
geo.MeshContainer = function(path, transfo, callback) {
if (callback === undefined && typeof transfo === 'function') {
callback = transfo;
transfo = {translation: {x:0,y:0,z:0}, rotation: {x:0,y:0,z:0}};
}
if (transfo === undefined) {
transfo = {translation: {x:0,y:0,z:0}, rotation: {x:0,y:0,z:0}};
}
/**
* array of each part of the mesh
@@ -44,6 +104,8 @@ geo.MeshContainer = function(path, callback) {
*/
this.numberOfFaces = 0;
this.transfo = transfo;
this.callback = callback;
if (path !== undefined) {
@@ -92,6 +154,12 @@ geo.MeshContainer.prototype.loadFromFile = function(path) {
// Just a simple vertex
var vertex = new geo.Vertex(line);
var vertexTransformed = applyTransformation(vertex, self.transfo);
vertex.x = vertexTransformed.x;
vertex.y = vertexTransformed.y;
vertex.z = vertexTransformed.z;
vertex.index = self.vertices.length;
self.vertices.push(vertex);
@@ -152,7 +220,7 @@ geo.MeshContainer.prototype.loadFromFile = function(path) {
function trySetLoaded() {
for (var name in availableMeshNames) {
if (availableMeshNames[name] === false) {
if (availableMeshNames[name].done === false) {
return;
@@ -160,15 +228,54 @@ function trySetLoaded() {
}
Log.ready("All meshes are ready");
Log.ready("Meshes loaded in " + (Date.now() - start) + 'ms');
}
var availableMeshNames = {
'/static/data/castle/princess peaches castle (outside).obj':false,
'/static/data/mountain/coocoolmountain.obj':false,
'/static/data/whomp/Whomps Fortress.obj':false,
'/static/data/bobomb/bobomb battlefeild.obj':false,
'/static/data/sponza/sponza.obj':false
'/static/data/castle/princess peaches castle (outside).obj': {
done: false
},
'/static/data/mountain/coocoolmountain.obj': {
done: false
},
'/static/data/whomp/Whomps Fortress.obj': {
done: false,
transfo: {
rotation: {
x: -Math.PI / 2,
y: 0,
z: Math.PI / 2
},
translation: {
x: 0,
y: 0,
z: 0
},
scale: 0.1
}
},
'/static/data/bobomb/bobomb battlefeild.obj': {
done: false,
transfo: {
rotation: {
x: 0,
y: Math.PI - 0.27,
z: 0
},
translation: {
x: 0,
y: 0,
z: 0
}
}
},
'/static/data/sponza/sponza.obj': {
done: false
}
};
for (var i = 1; i < 26; i++) {
@@ -179,12 +286,18 @@ for (var i = 1; i < 26; i++) {
geo.availableMeshes = {};
var start = Date.now();
function pushMesh(name) {
geo.availableMeshes[name] = new geo.MeshContainer(name.substring(1, name.length), function() {
availableMeshNames[name] = true;
trySetLoaded();
});
geo.availableMeshes[name] = new geo.MeshContainer(
name.substring(1, name.length),
availableMeshNames[name].transfo,
function() {
availableMeshNames[name].done = true;
trySetLoaded();
}
);
}