Some cleaning 😢
This commit is contained in:
parent
59518eb702
commit
5e0a6c3121
|
@ -138,6 +138,8 @@ L3D.PointerCamera = function() {
|
|||
*/
|
||||
this.listenerTarget = listenerTarget;
|
||||
|
||||
this.movingToRecommendation = null;
|
||||
|
||||
// Set events from the document
|
||||
var self = this;
|
||||
var onKeyDown = function(event) {self.onKeyDown(event);};
|
||||
|
|
Before Width: | Height: | Size: 4.5 MiB After Width: | Height: | Size: 4.5 MiB |
|
@ -1,9 +1,9 @@
|
|||
OPT=--compilation_level SIMPLE_OPTIMIZATIONS
|
||||
|
||||
ifeq ($(TYPE),RELEASE)
|
||||
CLOSURE=java -jar ../utils/closure-compiler/closure-compiler.jar
|
||||
CLOSURE=java -jar ../../utils/closure-compiler/closure-compiler.jar
|
||||
else
|
||||
CLOSURE=../utils/simple-compiler/compiler.sh
|
||||
CLOSURE=../../utils/simple-compiler/compiler.sh
|
||||
endif
|
||||
|
||||
all: Geo
|
|
@ -1,4 +1,6 @@
|
|||
var Log = require('../lib/NodeLog.js');
|
||||
var L3D = require('../../static/js/l3d.min.js');
|
||||
var THREE = require('three');
|
||||
|
||||
function clone(vec) {
|
||||
return {x : vec.x, y : vec.y, z : vec.z};
|
||||
|
@ -110,7 +112,7 @@ geo.MeshContainer = function(path, transfo, callback) {
|
|||
|
||||
if (path !== undefined) {
|
||||
|
||||
this.loadFromFile(path);
|
||||
this.loadFromFile('../' + path);
|
||||
|
||||
}
|
||||
|
||||
|
@ -233,12 +235,18 @@ function trySetLoaded() {
|
|||
|
||||
var availableMeshNames = {
|
||||
'/static/data/castle/princess peaches castle (outside).obj': {
|
||||
done: false
|
||||
done: false,
|
||||
recommendations : L3D.createPeachRecommendations(1134, 768)
|
||||
|
||||
},
|
||||
'/static/data/mountain/coocoolmountain.obj': {
|
||||
done: false
|
||||
done: false,
|
||||
recommendations : L3D.createMountainRecommendations(1134, 768)
|
||||
},
|
||||
'/static/data/mountain/coocoolmountain_sub.obj': {
|
||||
done: false,
|
||||
recommendations : L3D.createMountainRecommendations(1134, 768)
|
||||
},
|
||||
|
||||
'/static/data/whomp/Whomps Fortress.obj': {
|
||||
done: false,
|
||||
transfo: {
|
||||
|
@ -253,9 +261,26 @@ var availableMeshNames = {
|
|||
z: 0
|
||||
},
|
||||
scale: 0.1
|
||||
}
|
||||
},
|
||||
recommendations : L3D.createWhompRecommendations(1134, 768)
|
||||
},
|
||||
'/static/data/whomp/Whomps Fortress_sub.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
|
||||
},
|
||||
recommendations : L3D.createWhompRecommendations(1134, 768)
|
||||
},
|
||||
|
||||
'/static/data/bobomb/bobomb battlefeild.obj': {
|
||||
done: false,
|
||||
transfo: {
|
||||
|
@ -269,7 +294,25 @@ var availableMeshNames = {
|
|||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations : L3D.createBobombRecommendations(1134, 768)
|
||||
},
|
||||
|
||||
'/static/data/bobomb/bobomb battlefeild_sub.obj': {
|
||||
done: false,
|
||||
transfo: {
|
||||
rotation: {
|
||||
x: 0,
|
||||
y: Math.PI - 0.27,
|
||||
z: 0
|
||||
},
|
||||
translation: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
},
|
||||
recommendations : L3D.createBobombRecommendations(1134, 768)
|
||||
},
|
||||
|
||||
'/static/data/sponza/sponza.obj': {
|
||||
|
@ -294,6 +337,36 @@ function pushMesh(name) {
|
|||
name.substring(1, name.length),
|
||||
availableMeshNames[name].transfo,
|
||||
function() {
|
||||
geo.availableMeshes[name].recommendations = [];
|
||||
|
||||
if (availableMeshNames[name].recommendations !== undefined) {
|
||||
|
||||
for (var i = 0; i < availableMeshNames[name].recommendations.length; i++) {
|
||||
|
||||
var reco = availableMeshNames[name].recommendations[i].camera;
|
||||
|
||||
reco.lookAt(reco.target);
|
||||
|
||||
reco.updateMatrix();
|
||||
reco.updateProjectionMatrix();
|
||||
reco.updateMatrixWorld();
|
||||
|
||||
reco.matrixWorldInverse.getInverse( reco.matrixWorld );
|
||||
|
||||
var frustum = new THREE.Frustum();
|
||||
var projScreenMatrix = new THREE.Matrix4();
|
||||
projScreenMatrix.multiplyMatrices(reco.projectionMatrix, reco.matrixWorldInverse);
|
||||
|
||||
frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(reco.projectionMatrix, reco.matrixWorldInverse));
|
||||
|
||||
geo.availableMeshes[name].recommendations.push({
|
||||
position: reco.position,
|
||||
frustum: frustum.planes
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
availableMeshNames[name].done = true;
|
||||
trySetLoaded();
|
||||
}
|
|
@ -1,3 +1,59 @@
|
|||
var THREE = require('three');
|
||||
var L3D = require('../../static/js/l3d.min.js');
|
||||
|
||||
function isInFrustum(element, planes) {
|
||||
|
||||
if (element instanceof Array) {
|
||||
|
||||
var outcodes = [];
|
||||
|
||||
for (var i = 0; i < element.length; i++) {
|
||||
|
||||
var vertex = element[i];
|
||||
var currentOutcode = "";
|
||||
|
||||
for (var j = 0; j < planes.length; j++) {
|
||||
|
||||
var plane = planes[j];
|
||||
|
||||
distance =
|
||||
plane.normal.x * vertex.x +
|
||||
plane.normal.y * vertex.y +
|
||||
plane.normal.z * vertex.z +
|
||||
plane.constant;
|
||||
|
||||
// if (distance < 0) {
|
||||
// exitToContinue = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
currentOutcode += distance > 0 ? '0' : '1';
|
||||
|
||||
}
|
||||
|
||||
outcodes.push(parseInt(currentOutcode,2));
|
||||
|
||||
}
|
||||
|
||||
// http://vterrain.org/LOD/culling.html
|
||||
// I have no idea what i'm doing
|
||||
// http://i.kinja-img.com/gawker-media/image/upload/japbcvpavbzau9dbuaxf.jpg
|
||||
// But it seems to work
|
||||
// EDIT : Not, this should be ok http://www.cs.unc.edu/~blloyd/comp770/Lecture07.pdf
|
||||
|
||||
if ((outcodes[0] | outcodes[1] | outcodes[2]) === 0) {
|
||||
return true;
|
||||
} else if ((outcodes[0] & outcodes[1] & outcodes[2]) !== 0) {
|
||||
return false;
|
||||
} else {
|
||||
// part of the triangle is inside the viewing volume
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
@ -97,6 +153,18 @@ geo.MeshStreamer = function(path) {
|
|||
|
||||
};
|
||||
|
||||
geo.MeshStreamer.prototype.isBackFace = function(camera, face) {
|
||||
|
||||
var directionCamera = L3D.Tools.diff(camera.target, camera.position);
|
||||
|
||||
var v1 = L3D.Tools.diff(this.mesh.vertices[face.b], this.mesh.vertices[face.a]);
|
||||
var v2 = L3D.Tools.diff(this.mesh.vertices[face.c], this.mesh.vertices[face.a]);
|
||||
|
||||
var normal = L3D.Tools.cross(v1, v2);
|
||||
|
||||
return L3D.Tools.dot(directionCamera, normal) > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compute a function that can compare two faces
|
||||
* @param {Camera} camera a camera seeing or not face
|
||||
|
@ -192,6 +260,13 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
|
||||
self.mesh = geo.availableMeshes[path];
|
||||
|
||||
if (self.mesh === undefined) {
|
||||
process.stderr.write('Wrong path for model : ' + path);
|
||||
socket.emit('refused');
|
||||
socket.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
self.meshFaces = new Array(self.mesh.meshes.length);
|
||||
|
||||
for (var i = 0; i < self.meshFaces.length; i++) {
|
||||
|
@ -203,15 +278,6 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
|||
|
||||
}
|
||||
|
||||
var regex = /.*\.\..*/;
|
||||
var filePath = path.substring(1, path.length);
|
||||
|
||||
if (regex.test(filePath)) {
|
||||
socket.emit('refused');
|
||||
socket.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('ok');
|
||||
|
||||
});
|
||||
|
@ -344,8 +410,8 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) {
|
|||
var mightBeCompletetlyFinished = true;
|
||||
|
||||
// BOOM
|
||||
if (camera != null)
|
||||
this.mesh.faces.sort(this.faceComparator(camera));
|
||||
// if (camera != null)
|
||||
// this.mesh.faces.sort(this.faceComparator(camera));
|
||||
|
||||
for (var faceIndex = 0; faceIndex < this.mesh.faces.length; faceIndex++) {
|
||||
|
||||
|
@ -355,64 +421,30 @@ geo.MeshStreamer.prototype.nextElements = function(_camera, force) {
|
|||
|
||||
continue;
|
||||
|
||||
} else {
|
||||
|
||||
mightBeCompletetlyFinished = false;
|
||||
|
||||
}
|
||||
|
||||
mightBeCompletetlyFinished = false;
|
||||
|
||||
var vertex1 = this.mesh.vertices[currentFace.a];
|
||||
var vertex2 = this.mesh.vertices[currentFace.b];
|
||||
var vertex3 = this.mesh.vertices[currentFace.c];
|
||||
|
||||
if (!force) {
|
||||
if (!force && camera !== null) {
|
||||
|
||||
var display = false;
|
||||
var outcodes = [];
|
||||
var exitToContinue = false;
|
||||
threeVertices = [vertex1, vertex2, vertex3];
|
||||
|
||||
for (i = 0; i < threeVertices.length; i++) {
|
||||
|
||||
var vertex = threeVertices[i];
|
||||
var currentOutcode = "";
|
||||
|
||||
for (var j = 0; j < planes.length; j++) {
|
||||
|
||||
var plane = planes[j];
|
||||
|
||||
distance =
|
||||
plane.normal.x * vertex.x +
|
||||
plane.normal.y * vertex.y +
|
||||
plane.normal.z * vertex.z +
|
||||
plane.constant;
|
||||
|
||||
// if (distance < 0) {
|
||||
// exitToContinue = true;
|
||||
// break;
|
||||
// }
|
||||
|
||||
currentOutcode += distance > 0 ? '0' : '1';
|
||||
|
||||
}
|
||||
|
||||
outcodes.push(parseInt(currentOutcode,2));
|
||||
|
||||
}
|
||||
|
||||
// http://vterrain.org/LOD/culling.html
|
||||
// I have no idea what i'm doing
|
||||
// http://i.kinja-img.com/gawker-media/image/upload/japbcvpavbzau9dbuaxf.jpg
|
||||
// But it seems to work
|
||||
if ( (outcodes[0] | outcodes[1]) === 0 && (outcodes[1] | outcodes[2]) === 0 ) {
|
||||
// all points in
|
||||
} else if ( (outcodes[0] === outcodes[1]) && (outcodes[0] === outcodes[2]) ) {
|
||||
// all points out
|
||||
// Frustum culling
|
||||
if (!isInFrustum(threeVertices, planes)) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// part of the triangle is inside the viewing volume
|
||||
|
||||
// Backface culling
|
||||
if (this.isBackFace(camera, currentFace)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!this.vertices[currentFace.a]) {
|
|
@ -0,0 +1 @@
|
|||
[[0,0.07894736842105263,0.18421052631578946,0,0.02631578947368421,0.02631578947368421,0,0.02631578947368421,0,0.13157894736842105,0.2894736842105263,0.2631578947368421],[0,0,0.10526315789473684,0.15789473684210525,0.18421052631578946,0.02631578947368421,0,0.07894736842105263,0.02631578947368421,0.05263157894736842,0.05263157894736842,0.05263157894736842],[0,0.02631578947368421,0,0.5,0.02631578947368421,0.02631578947368421,0.02631578947368421,0.07894736842105263,0.02631578947368421,0.07894736842105263,0.07894736842105263,0.05263157894736842],[0,0.05263157894736842,0.07894736842105263,0,0.4473684210526316,0.02631578947368421,0.13157894736842105,0.02631578947368421,0,0.07894736842105263,0,0.13157894736842105],[0,0,0.02631578947368421,0.15789473684210525,0,0.3157894736842105,0.21052631578947367,0.05263157894736842,0,0.07894736842105263,0,0.10526315789473684],[0,0.10526315789473684,0,0.05263157894736842,0.13157894736842105,0,0.13157894736842105,0.05263157894736842,0.15789473684210525,0.02631578947368421,0.02631578947368421,0.02631578947368421],[0,0.15789473684210525,0.10526315789473684,0,0,0.10526315789473684,0,0.05263157894736842,0.21052631578947367,0.13157894736842105,0,0],[0,0.07894736842105263,0.05263157894736842,0.02631578947368421,0.07894736842105263,0.07894736842105263,0.10526315789473684,0,0.07894736842105263,0.02631578947368421,0.02631578947368421,0.05263157894736842],[0,0,0.10526315789473684,0.02631578947368421,0.02631578947368421,0.18421052631578946,0.15789473684210525,0,0,0.21052631578947367,0.07894736842105263,0.07894736842105263],[0,0.07894736842105263,0.10526315789473684,0.02631578947368421,0,0,0.07894736842105263,0.15789473684210525,0.13157894736842105,0,0.21052631578947367,0.07894736842105263],[0,0.02631578947368421,0.10526315789473684,0.07894736842105263,0.05263157894736842,0.02631578947368421,0,0.02631578947368421,0.23684210526315788,0.07894736842105263,0,0.10526315789473684],[0,0.18421052631578946,0.13157894736842105,0.13157894736842105,0.10526315789473684,0.02631578947368421,0,0.13157894736842105,0.02631578947368421,0.05263157894736842,0.07894736842105263,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,602,0,0,0,0,0,0,151,191,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,1116,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,87,0,0,0,0,0,0,0,0,0,82],[0,0,0,0,0,0,0,0,195,0,0,0],[0,86,41,0,0,0,0,0,0,563,74,72],[0,0,59,0,0,0,0,0,0,0,0,49],[0,147,151,0,0,0,0,0,0,0,0,110],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.03125,0.09375,0.5,0.21875,0.03125,0.09375,0.1875,0,0.125,0.15625,0],[0,0,0.15625,0.0625,0.21875,0.0625,0.15625,0.09375,0,0.0625,0.03125,0],[0,0.21875,0,0.0625,0.0625,0,0,0,0,0,0.03125,0.0625],[0,0.09375,0.0625,0,0.25,0.03125,0.1875,0.1875,0.03125,0.25,0,0.03125],[0,0.125,0.0625,0.125,0,0.03125,0,0,0.1875,0.09375,0.15625,0.0625],[0,0.03125,0,0,0,0,0.21875,0,0.25,0,0,0.1875],[0,0.03125,0.0625,0.0625,0.03125,0.34375,0,0.125,0.34375,0,0.40625,0.0625],[0,0.125,0,0.15625,0,0.0625,0.25,0,0.03125,0.09375,0,0],[0,0.125,0.03125,0.0625,0,0.1875,0.15625,0.03125,0,0.0625,0,0.25],[0,0.1875,0,0.125,0.125,0,0.0625,0.03125,0,0,0.03125,0.125],[0,0.0625,0.0625,0.03125,0.09375,0,0.46875,0.09375,0.03125,0.09375,0,0.1875],[0,0,0.0625,0.0625,0,0,0,0.03125,0.1875,0.125,0.46875,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,0,218,0,0,0,0,0,0,0,0],[0,0,0,106,36,0,0,182,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,3,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,72],[0,0,0,0,0,0,0,0,0,0,0,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.05555555555555555,0.08333333333333333,0,0.16666666666666666,0.027777777777777776,0.5,0,0.05555555555555555,0.027777777777777776,0],[0,0,0.05555555555555555,0.08333333333333333,0.08333333333333333,0,0.08333333333333333,0,0.027777777777777776,0.027777777777777776,0],[0,0.05555555555555555,0,0.1111111111111111,0.027777777777777776,0,0.027777777777777776,0,0.027777777777777776,0.027777777777777776,0],[0,0.05555555555555555,0.027777777777777776,0,0.1111111111111111,0,0.027777777777777776,0.027777777777777776,0.08333333333333333,0.027777777777777776,0],[0,0.08333333333333333,0,0.1111111111111111,0,0.3888888888888889,0,0.16666666666666666,0.05555555555555555,0.027777777777777776,0.05555555555555555],[0,0,0,0.027777777777777776,0.25,0,0.1111111111111111,0.1388888888888889,0,0,0.2222222222222222],[0,0.05555555555555555,0.08333333333333333,0.1388888888888889,0,0.027777777777777776,0,0.027777777777777776,0.08333333333333333,0.16666666666666666,0.3055555555555556],[0,0.027777777777777776,0.027777777777777776,0,0.027777777777777776,0.1388888888888889,0.05555555555555555,0,0.08333333333333333,0.05555555555555555,0.027777777777777776],[0,0,0,0,0.08333333333333333,0.05555555555555555,0.1111111111111111,0.05555555555555555,0,0.1111111111111111,0.1111111111111111],[0,0.027777777777777776,0.027777777777777776,0.027777777777777776,0.16666666666666666,0,0.05555555555555555,0.027777777777777776,0.1388888888888889,0,0],[0,0,0.027777777777777776,0,0.1388888888888889,0.16666666666666666,0.1111111111111111,0.08333333333333333,0.1111111111111111,0,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,0,0,0,0,70,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,12,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,10,0,0,0,0,0,0,0],[0,0,0,0,0,83,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,64],[0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,36,0,0,0,16,0,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.1,0.3,0,0,0,0,0,0,0.1,0.4,0.5],[0,0,0.1,0.2,0.2,0,0,0.2,0,0.1,0.1,0],[0,0.1,0,0.4,0,0,0.1,0.3,0.1,0.1,0.1,0],[0,0.1,0,0,0.4,0.1,0.2,0,0,0.1,0,0.2],[0,0,0,0.2,0,0.5,0.1,0,0,0.1,0,0],[0,0,0,0,0.3,0,0.1,0,0.3,0.1,0.1,0.1],[0,0.3,0.1,0,0,0,0,0.1,0.4,0.1,0,0],[0,0.1,0.1,0,0.1,0,0.4,0,0,0,0.1,0.2],[0,0,0.3,0,0,0.3,0.1,0,0,0.3,0.1,0],[0,0.1,0.1,0,0,0,0.1,0.4,0,0,0.2,0.1],[0,0,0.2,0.2,0.1,0.1,0,0.1,0.3,0,0,0],[0,0.2,0.2,0.3,0,0,0,0.1,0,0.1,0.1,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,0.1,0.5,0.3,0,0.1,0.1,0,0.2,0,0],[0,0,0.2,0.1,0.1,0,0.3,0.2,0,0.2,0,0],[0,0.2,0,0.1,0.2,0,0,0,0,0,0,0.1],[0,0.1,0.1,0,0.4,0,0,0.2,0,0.3,0,0],[0,0.2,0,0,0,0.1,0,0,0.4,0.1,0.2,0.1],[0,0.1,0,0,0,0,0.1,0,0.4,0,0,0.2],[0,0.1,0,0,0.1,0.4,0,0.1,0.1,0,0.3,0.1],[0,0,0,0.3,0,0.1,0.2,0,0,0,0,0],[0,0.2,0.1,0.1,0,0.2,0.2,0,0,0,0,0.2],[0,0.3,0,0.1,0.1,0,0.1,0,0,0,0.1,0],[0,0.1,0.1,0,0,0,0.3,0.1,0,0.1,0,0.2],[0,0,0.1,0.1,0,0,0,0,0.1,0,0.5,0]]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.16666666666666666,0.16666666666666666,0,0.16666666666666666,0,0.5,0,0,0,0],[0,0,0.16666666666666666,0.16666666666666666,0,0,0,0,0.16666666666666666,0.16666666666666666,0],[0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0.16666666666666666,0,0,0,0],[0,0.16666666666666666,0.16666666666666666,0,0,0,0,0.16666666666666666,0.16666666666666666,0.16666666666666666,0],[0,0,0,0.3333333333333333,0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0],[0,0,0,0.16666666666666666,0.5,0,0,0,0,0,0.3333333333333333],[0,0,0.16666666666666666,0.16666666666666666,0,0,0,0,0,0,0.5],[0,0,0,0,0,0.3333333333333333,0.16666666666666666,0,0.16666666666666666,0,0],[0,0,0,0,0,0.16666666666666666,0.16666666666666666,0,0,0.5,0.16666666666666666],[0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0,0,0.3333333333333333,0,0],[0,0,0,0,0,0.3333333333333333,0.16666666666666666,0.3333333333333333,0.16666666666666666,0,0]]
|
|
@ -0,0 +1,141 @@
|
|||
"use strict";
|
||||
|
||||
let fs = require('fs');
|
||||
|
||||
class OutOfBoundError extends Error {
|
||||
constructor(matrix, i, j) {
|
||||
super(`Index array out of bound (${i},${j}) exceeds (${matrix.lines}, ${matrix.columns}).`);
|
||||
this.name = 'OutOfBoundError';
|
||||
}
|
||||
}
|
||||
|
||||
class Matrix {
|
||||
constructor(lines, columns) {
|
||||
// this.lines = lines;
|
||||
// this.columns = columns;
|
||||
|
||||
this.data = [];
|
||||
|
||||
for (let i = 0; i < lines; i++) {
|
||||
let line = [];
|
||||
for (let j = 0; j < columns; j++) {
|
||||
line.push(0);
|
||||
}
|
||||
this.data.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
get(i, j) {
|
||||
// if (i >= this.lines || j >= this.columns || i < 0 || j < 0 ) {
|
||||
// this._throwOutOfBoundError(i,j);
|
||||
// }
|
||||
return this.data[i][j];
|
||||
}
|
||||
|
||||
set(i, j, value) {
|
||||
// if (i >= this.lines || j >= this.columns || i < 0 || j < 0 ) {
|
||||
// this._throwOutOfBoundError(i,j);
|
||||
// }
|
||||
return this.data[i][j] = value;
|
||||
}
|
||||
|
||||
print(type) {
|
||||
if (type === 'matlab') {
|
||||
|
||||
let maxColumns = 0;
|
||||
|
||||
for (let i = 0; i < this.data.length; i++) {
|
||||
if (this.data[i].length > maxColumns)
|
||||
maxColumns = this.data[i].length;
|
||||
}
|
||||
|
||||
let str = '[';
|
||||
|
||||
for (let i = 0; i < this.data.length; i++) {
|
||||
str += '[';
|
||||
for (let j = 0; j < maxColumns; j++) {
|
||||
str +=
|
||||
(this.data[i][j] !== undefined ? this.data[i][j] : 0) +
|
||||
(j === maxColumns - 1 ? ']' : ',');
|
||||
}
|
||||
str += (i === this.data.length - 1 ? ']' : ';');
|
||||
}
|
||||
|
||||
console.log(str + ';');
|
||||
|
||||
return;
|
||||
}
|
||||
// for (let i = 0; i < this.lines; i++) {
|
||||
// for (let j = 0; j < this.columns; j++) {
|
||||
// process.stdout.write(this.get(i,j) + ' ');
|
||||
// }
|
||||
// process.stdout.write('\n');
|
||||
// }
|
||||
}
|
||||
|
||||
toArray() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
fromArray(array) {
|
||||
|
||||
// if (! array instanceof Array)
|
||||
// throw new TypeError('Parameter is not an array');
|
||||
|
||||
// let columns = null;
|
||||
// for (let line of array) {
|
||||
// if (! line instanceof Array)
|
||||
// throw new TypeError('Parameter is not an array of array');
|
||||
|
||||
// if (columns === null) {
|
||||
// columns = line.length;
|
||||
// } else if (columns !== line.length) {
|
||||
// throw new Typerror('The lines have not the same size');
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
this.data = array;
|
||||
|
||||
// this.columns = columns;
|
||||
// this.lines = array.length;
|
||||
|
||||
}
|
||||
|
||||
saveToFile(path, type) {
|
||||
if (type === 'matlab') {
|
||||
fs.writeFileSync(path, JSON.stringify(this.data).replace('],', '];'));
|
||||
return;
|
||||
}
|
||||
fs.writeFileSync(path, JSON.stringify(this.data));
|
||||
}
|
||||
|
||||
loadFromFile(path) {
|
||||
this.fromArray(JSON.parse(fs.readFileSync(path, 'utf-8')));
|
||||
}
|
||||
|
||||
_throwOutOfBoundError(i,j) {
|
||||
throw new OutOfBoundError(this, i, j);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Matrix;
|
||||
|
||||
function main() {
|
||||
|
||||
var m = new Matrix(2,3);
|
||||
m.set(1,2,3);
|
||||
m.print();
|
||||
m.saveToFile('tests/myMatrix.json');
|
||||
|
||||
console.log('----');
|
||||
|
||||
var m2 = new Matrix();
|
||||
m2.loadFromFile('tests/myMatrix.json');
|
||||
m2.print();
|
||||
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
"use strict";
|
||||
|
||||
let fs = require('fs');
|
||||
let THREE = require('three');
|
||||
let L3D = require('../static/js/l3d.min.js');
|
||||
|
||||
function serialize(object) {
|
||||
|
||||
let data = {};
|
||||
|
||||
data.vertices = object.children[0].geometry.vertices;
|
||||
|
||||
data.children = [];
|
||||
|
||||
for (let objChild of object.children) {
|
||||
|
||||
let newChild = {};
|
||||
|
||||
// newChild.faceVertexUvs = objChild.geometry.faceVertexUvs;
|
||||
newChild.faces = objChild.geometry.faces;
|
||||
|
||||
data.children.push(newChild);
|
||||
|
||||
}
|
||||
|
||||
return JSON.stringify(data);
|
||||
|
||||
}
|
||||
|
||||
function deserialize(str) {
|
||||
|
||||
let parse = JSON.parse(str);
|
||||
let vertices = [];
|
||||
let material = new THREE.MeshBasicMaterial();
|
||||
|
||||
let ret = new THREE.Object3D();
|
||||
|
||||
for (let vertex of parse.vertices) {
|
||||
|
||||
vertices.push(new THREE.Vector3(vertex.x, vertex.y, vertex.z));
|
||||
|
||||
}
|
||||
|
||||
|
||||
for (let parseChild of parse.children) {
|
||||
|
||||
let geometry = new THREE.Geometry();
|
||||
geometry.vertices = vertices;
|
||||
|
||||
for (let face of parseChild.faces) {
|
||||
|
||||
geometry.faces.push(new THREE.Face3(face.a, face.b, face.c));
|
||||
|
||||
}
|
||||
|
||||
geometry.computeBoundingSphere();
|
||||
let newChild = new THREE.Mesh(geometry, material);
|
||||
|
||||
ret.children.push(newChild);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
function serializeToFile(path, obj) {
|
||||
|
||||
fs.writeFileSync(path, serialize(obj));
|
||||
|
||||
}
|
||||
|
||||
function loadFromFile(path) {
|
||||
|
||||
return deserialize(fs.readFileSync(path, 'utf-8'));
|
||||
|
||||
}
|
||||
|
||||
module.exports.serialize = serialize;
|
||||
module.exports.deserialize = deserialize;
|
||||
module.exports.serializeToFile = serializeToFile;
|
||||
module.exports.loadFromFile = loadFromFile;
|
||||
|
||||
function main() {
|
||||
|
||||
let loader = new L3D.ProgressiveLoader(
|
||||
'/static/data/castle/princess peaches castle (outside).obj',
|
||||
new THREE.Object3D(),
|
||||
null
|
||||
);
|
||||
|
||||
loader.load(function() {
|
||||
console.log("Loaded");
|
||||
// console.log(loader.obj.children[0].geometry);
|
||||
deserialize(serialize(loader.obj));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
[[0,0.07894736842105263,0.18421052631578946,0,0.02631578947368421,0.02631578947368421,0,0.02631578947368421,0,0.13157894736842105,0.2894736842105263,0.2631578947368421],[0,0,0.10526315789473684,0.15789473684210525,0.18421052631578946,0.02631578947368421,0,0.07894736842105263,0.02631578947368421,0.05263157894736842,0.05263157894736842,0.05263157894736842],[0,0.02631578947368421,0,0.5,0.02631578947368421,0.02631578947368421,0.02631578947368421,0.07894736842105263,0.02631578947368421,0.07894736842105263,0.07894736842105263,0.05263157894736842],[0,0.05263157894736842,0.07894736842105263,0,0.4473684210526316,0.02631578947368421,0.13157894736842105,0.02631578947368421,0,0.07894736842105263,0,0.13157894736842105],[0,0,0.02631578947368421,0.15789473684210525,0,0.3157894736842105,0.21052631578947367,0.05263157894736842,0,0.07894736842105263,0,0.10526315789473684],[0,0.10526315789473684,0,0.05263157894736842,0.13157894736842105,0,0.13157894736842105,0.05263157894736842,0.15789473684210525,0.02631578947368421,0.02631578947368421,0.02631578947368421],[0,0.15789473684210525,0.10526315789473684,0,0,0.10526315789473684,0,0.05263157894736842,0.21052631578947367,0.13157894736842105,0,0],[0,0.07894736842105263,0.05263157894736842,0.02631578947368421,0.07894736842105263,0.07894736842105263,0.10526315789473684,0,0.07894736842105263,0.02631578947368421,0.02631578947368421,0.05263157894736842],[0,0,0.10526315789473684,0.02631578947368421,0.02631578947368421,0.18421052631578946,0.15789473684210525,0,0,0.21052631578947367,0.07894736842105263,0.07894736842105263],[0,0.07894736842105263,0.10526315789473684,0.02631578947368421,0,0,0.07894736842105263,0.15789473684210525,0.13157894736842105,0,0.21052631578947367,0.07894736842105263],[0,0.02631578947368421,0.10526315789473684,0.07894736842105263,0.05263157894736842,0.02631578947368421,0,0.02631578947368421,0.23684210526315788,0.07894736842105263,0,0.10526315789473684],[0,0.18421052631578946,0.13157894736842105,0.13157894736842105,0.10526315789473684,0.02631578947368421,0,0.13157894736842105,0.02631578947368421,0.05263157894736842,0.07894736842105263,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.03125,0.09375,0.5,0.21875,0.03125,0.09375,0.1875,0,0.125,0.15625,0],[0,0,0.15625,0.0625,0.21875,0.0625,0.15625,0.09375,0,0.0625,0.03125,0],[0,0.21875,0,0.0625,0.0625,0,0,0,0,0,0.03125,0.0625],[0,0.09375,0.0625,0,0.25,0.03125,0.1875,0.1875,0.03125,0.25,0,0.03125],[0,0.125,0.0625,0.125,0,0.03125,0,0,0.1875,0.09375,0.15625,0.0625],[0,0.03125,0,0,0,0,0.21875,0,0.25,0,0,0.1875],[0,0.03125,0.0625,0.0625,0.03125,0.34375,0,0.125,0.34375,0,0.40625,0.0625],[0,0.125,0,0.15625,0,0.0625,0.25,0,0.03125,0.09375,0,0],[0,0.125,0.03125,0.0625,0,0.1875,0.15625,0.03125,0,0.0625,0,0.25],[0,0.1875,0,0.125,0.125,0,0.0625,0.03125,0,0,0.03125,0.125],[0,0.0625,0.0625,0.03125,0.09375,0,0.46875,0.09375,0.03125,0.09375,0,0.1875],[0,0,0.0625,0.0625,0,0,0,0.03125,0.1875,0.125,0.46875,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.05555555555555555,0.08333333333333333,0,0.16666666666666666,0.027777777777777776,0.5,0,0.05555555555555555,0.027777777777777776,0],[0,0,0.05555555555555555,0.08333333333333333,0.08333333333333333,0,0.08333333333333333,0,0.027777777777777776,0.027777777777777776,0],[0,0.05555555555555555,0,0.1111111111111111,0.027777777777777776,0,0.027777777777777776,0,0.027777777777777776,0.027777777777777776,0],[0,0.05555555555555555,0.027777777777777776,0,0.1111111111111111,0,0.027777777777777776,0.027777777777777776,0.08333333333333333,0.027777777777777776,0],[0,0.08333333333333333,0,0.1111111111111111,0,0.3888888888888889,0,0.16666666666666666,0.05555555555555555,0.027777777777777776,0.05555555555555555],[0,0,0,0.027777777777777776,0.25,0,0.1111111111111111,0.1388888888888889,0,0,0.2222222222222222],[0,0.05555555555555555,0.08333333333333333,0.1388888888888889,0,0.027777777777777776,0,0.027777777777777776,0.08333333333333333,0.16666666666666666,0.3055555555555556],[0,0.027777777777777776,0.027777777777777776,0,0.027777777777777776,0.1388888888888889,0.05555555555555555,0,0.08333333333333333,0.05555555555555555,0.027777777777777776],[0,0,0,0,0.08333333333333333,0.05555555555555555,0.1111111111111111,0.05555555555555555,0,0.1111111111111111,0.1111111111111111],[0,0.027777777777777776,0.027777777777777776,0.027777777777777776,0.16666666666666666,0,0.05555555555555555,0.027777777777777776,0.1388888888888889,0,0],[0,0,0.027777777777777776,0,0.1388888888888889,0.16666666666666666,0.1111111111111111,0.08333333333333333,0.1111111111111111,0,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.1,0.3,0,0,0,0,0,0,0.1,0.4,0.5],[0,0,0.1,0.2,0.2,0,0,0.2,0,0.1,0.1,0],[0,0.1,0,0.4,0,0,0.1,0.3,0.1,0.1,0.1,0],[0,0.1,0,0,0.4,0.1,0.2,0,0,0.1,0,0.2],[0,0,0,0.2,0,0.5,0.1,0,0,0.1,0,0],[0,0,0,0,0.3,0,0.1,0,0.3,0.1,0.1,0.1],[0,0.3,0.1,0,0,0,0,0.1,0.4,0.1,0,0],[0,0.1,0.1,0,0.1,0,0.4,0,0,0,0.1,0.2],[0,0,0.3,0,0,0.3,0.1,0,0,0.3,0.1,0],[0,0.1,0.1,0,0,0,0.1,0.4,0,0,0.2,0.1],[0,0,0.2,0.2,0.1,0.1,0,0.1,0.3,0,0,0],[0,0.2,0.2,0.3,0,0,0,0.1,0,0.1,0.1,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,0.1,0.5,0.3,0,0.1,0.1,0,0.2,0,0],[0,0,0.2,0.1,0.1,0,0.3,0.2,0,0.2,0,0],[0,0.2,0,0.1,0.2,0,0,0,0,0,0,0.1],[0,0.1,0.1,0,0.4,0,0,0.2,0,0.3,0,0],[0,0.2,0,0,0,0.1,0,0,0.4,0.1,0.2,0.1],[0,0.1,0,0,0,0,0.1,0,0.4,0,0,0.2],[0,0.1,0,0,0.1,0.4,0,0.1,0.1,0,0.3,0.1],[0,0,0,0.3,0,0.1,0.2,0,0,0,0,0],[0,0.2,0.1,0.1,0,0.2,0.2,0,0,0,0,0.2],[0,0.3,0,0.1,0.1,0,0.1,0,0,0,0.1,0],[0,0.1,0.1,0,0,0,0.3,0.1,0,0.1,0,0.2],[0,0,0.1,0.1,0,0,0,0,0.1,0,0.5,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0.16666666666666666,0.16666666666666666,0,0.16666666666666666,0,0.5,0,0,0,0],[0,0,0.16666666666666666,0.16666666666666666,0,0,0,0,0.16666666666666666,0.16666666666666666,0],[0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0.16666666666666666,0,0,0,0],[0,0.16666666666666666,0.16666666666666666,0,0,0,0,0.16666666666666666,0.16666666666666666,0.16666666666666666,0],[0,0,0,0.3333333333333333,0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0],[0,0,0,0.16666666666666666,0.5,0,0,0,0,0,0.3333333333333333],[0,0,0.16666666666666666,0.16666666666666666,0,0,0,0,0,0,0.5],[0,0,0,0,0,0.3333333333333333,0.16666666666666666,0,0.16666666666666666,0,0],[0,0,0,0,0,0.16666666666666666,0.16666666666666666,0,0,0.5,0.16666666666666666],[0,0.16666666666666666,0,0.16666666666666666,0.16666666666666666,0,0,0,0.3333333333333333,0,0],[0,0,0,0,0,0.3333333333333333,0.16666666666666666,0.3333333333333333,0.16666666666666666,0,0],]
|
|
@ -0,0 +1 @@
|
|||
[[0,0,0],[0,0,3]]
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue