Cleaning
This commit is contained in:
parent
d8d1c54fed
commit
e5e1513221
|
@ -0,0 +1,12 @@
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @namespace
|
||||||
|
*/
|
||||||
|
var geo = {};
|
||||||
|
|
||||||
|
if (typeof module === 'object') {
|
||||||
|
|
||||||
|
module.exports = geo;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
OPT=--compilation_level SIMPLE_OPTIMIZATIONS
|
||||||
|
|
||||||
|
ifeq ($(TYPE),RELEASE)
|
||||||
|
CLOSURE=java -jar /usr/share/java/closure-compiler/closure-compiler.jar
|
||||||
|
else
|
||||||
|
CLOSURE=../utils/compiler.sh
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: Geo
|
||||||
|
|
||||||
|
Geo:
|
||||||
|
$(CLOSURE) $(OPT) \
|
||||||
|
--js Geo.js \
|
||||||
|
--js Mesh.js \
|
||||||
|
--js MeshContainer.js \
|
||||||
|
--js MeshStreamer.js \
|
||||||
|
--js_output_file ../lib/geo.min.js
|
132
geo/Mesh.js
132
geo/Mesh.js
|
@ -1,14 +1,9 @@
|
||||||
/**
|
|
||||||
* @namespace
|
|
||||||
*/
|
|
||||||
var mesh = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reprensents a mesh
|
* Reprensents a mesh
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
mesh.Mesh = function() {
|
geo.Mesh = function() {
|
||||||
this.vertices = [];
|
this.vertices = [];
|
||||||
this.faces = [];
|
this.faces = [];
|
||||||
this.texCoords = [];
|
this.texCoords = [];
|
||||||
|
@ -23,7 +18,7 @@ mesh.Mesh = function() {
|
||||||
* Checks if there are normals in the mesh
|
* Checks if there are normals in the mesh
|
||||||
* @returns {Boolean} true if there are normals in the mesh, false otherwise
|
* @returns {Boolean} true if there are normals in the mesh, false otherwise
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.hasNormals = function() {
|
geo.Mesh.prototype.hasNormals = function() {
|
||||||
return this.normals.length > 0;
|
return this.normals.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,22 +26,22 @@ mesh.Mesh.prototype.hasNormals = function() {
|
||||||
* Checks if there are texture coordinates in the mesh
|
* Checks if there are texture coordinates in the mesh
|
||||||
* @returns {Boolean} true if there are texture coordinates in the mesh, false otherwise
|
* @returns {Boolean} true if there are texture coordinates in the mesh, false otherwise
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.hasTexCoords = function() {
|
geo.Mesh.prototype.hasTexCoords = function() {
|
||||||
return this.texCoords.length > 0;
|
return this.texCoords.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a vertex to a mesh
|
* Adds a vertex to a mesh
|
||||||
* @param {mesh.Vertex|String} A Vertex object or its string representation
|
* @param {geo.Vertex|String} A Vertex object or its string representation
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.addVertex = function(vertex) {
|
geo.Mesh.prototype.addVertex = function(vertex) {
|
||||||
|
|
||||||
if (vertex instanceof mesh.Vertex) {
|
if (vertex instanceof geo.Vertex) {
|
||||||
this.vertices.push(vertex);
|
this.vertices.push(vertex);
|
||||||
} else if (typeof vertex === 'string' || vertex instanceof String) {
|
} else if (typeof vertex === 'string' || vertex instanceof String) {
|
||||||
this.vertices.push(new mesh.Vertex(vertex));
|
this.vertices.push(new geo.Vertex(vertex));
|
||||||
} else {
|
} else {
|
||||||
console.error("Can only add vertex from mesh.Vertex or string");
|
console.error("Can only add vertex from geo.Vertex or string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,18 +50,18 @@ mesh.Mesh.prototype.addVertex = function(vertex) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a face to a mesh
|
* Adds a face to a mesh
|
||||||
* @param {mesh.Face|String} A Face object or its string representation
|
* @param {geo.Face|String} A Face object or its string representation
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.addFaces = function(face) {
|
geo.Mesh.prototype.addFaces = function(face) {
|
||||||
var faces;
|
var faces;
|
||||||
|
|
||||||
if (face instanceof mesh.Face) {
|
if (face instanceof geo.Face) {
|
||||||
this.faces.push(face);
|
this.faces.push(face);
|
||||||
} else if (typeof face === 'string' || face instanceof String) {
|
} else if (typeof face === 'string' || face instanceof String) {
|
||||||
faces = parseFace(face);
|
faces = parseFace(face);
|
||||||
this.faces = this.faces.concat(faces);
|
this.faces = this.faces.concat(faces);
|
||||||
} else {
|
} else {
|
||||||
console.error("Can only add face from mesh.Face or string");
|
console.error("Can only add face from geo.Face or string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,15 +74,15 @@ mesh.Mesh.prototype.addFaces = function(face) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a texture coordinate to a mesh
|
* Adds a texture coordinate to a mesh
|
||||||
* @param {mesh.TexCoord|String} A TexCoord object or its string representation
|
* @param {geo.TexCoord|String} A TexCoord object or its string representation
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.addTexCoord = function(texCoord) {
|
geo.Mesh.prototype.addTexCoord = function(texCoord) {
|
||||||
if (texCoord instanceof mesh.TexCoord) {
|
if (texCoord instanceof geo.TexCoord) {
|
||||||
this.texCoords.push(texCoord);
|
this.texCoords.push(texCoord);
|
||||||
} else if (typeof texCoord === 'string' || texCoord instanceof String) {
|
} else if (typeof texCoord === 'string' || texCoord instanceof String) {
|
||||||
this.texCoords.push(new mesh.TexCoord(texCoord));
|
this.texCoords.push(new geo.TexCoord(texCoord));
|
||||||
} else {
|
} else {
|
||||||
console.error("Can only add texCoord from mesh.TexCoord or string");
|
console.error("Can only add texCoord from geo.TexCoord or string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,31 +91,31 @@ mesh.Mesh.prototype.addTexCoord = function(texCoord) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a normal to a mesh
|
* Adds a normal to a mesh
|
||||||
* @param {mesh.Normal|String} A Normal object or its string representation
|
* @param {geo.Normal|String} A Normal object or its string representation
|
||||||
*/
|
*/
|
||||||
mesh.Mesh.prototype.addNormal = function(normal) {
|
geo.Mesh.prototype.addNormal = function(normal) {
|
||||||
if (normal instanceof mesh.Normal) {
|
if (normal instanceof geo.Normal) {
|
||||||
this.normals.push(normal);
|
this.normals.push(normal);
|
||||||
} else if (typeof normal === 'string' || normal instanceof String) {
|
} else if (typeof normal === 'string' || normal instanceof String) {
|
||||||
this.normals.push(new mesh.Normal(normal));
|
this.normals.push(new geo.Normal(normal));
|
||||||
} else {
|
} else {
|
||||||
console.error("Can only add normal from mesh.Normal of string");
|
console.error("Can only add normal from geo.Normal of string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.normals[this.normals.length - 1];
|
return this.normals[this.normals.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.Mesh.prototype.isFinished = function() {
|
geo.Mesh.prototype.isFinished = function() {
|
||||||
return this.faceIndex === this.faces.length;
|
return this.faceIndex === this.faces.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent a 3D vertex
|
* Represent a 3D vertex
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
mesh.Vertex = function() {
|
geo.Vertex = function() {
|
||||||
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
||||||
var split = arguments[0].replace(/\s+/g, " ").split(' ');
|
var split = arguments[0].replace(/\s+/g, " ").split(' ');
|
||||||
|
|
||||||
|
@ -155,11 +150,11 @@ mesh.Vertex = function() {
|
||||||
* @returns {Array} An array representing the vertex
|
* @returns {Array} An array representing the vertex
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var vertex = new mesh.Vertex('v 3.5 3.6 3.7');
|
* var vertex = new geo.Vertex('v 3.5 3.6 3.7');
|
||||||
* vertex.index = 5;
|
* vertex.index = 5;
|
||||||
* console.log(vertex.toList()); // Prints ['v', 5, 3.5, 3.6, 3.7]
|
* console.log(vertex.toList()); // Prints ['v', 5, 3.5, 3.6, 3.7]
|
||||||
*/
|
*/
|
||||||
mesh.Vertex.prototype.toList = function() {
|
geo.Vertex.prototype.toList = function() {
|
||||||
return ['v', this.index, this.x, this.y, this.z];
|
return ['v', this.index, this.x, this.y, this.z];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,37 +163,37 @@ mesh.Vertex.prototype.toList = function() {
|
||||||
* @returns {string} A string representing the vertex
|
* @returns {string} A string representing the vertex
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var vertex = new mesh.Vertex('v 3.5 3.6 3.7');
|
* var vertex = new geo.Vertex('v 3.5 3.6 3.7');
|
||||||
* console.log(vertex.toString()); // Prints v 3.5 3.6 3.7
|
* console.log(vertex.toString()); // Prints v 3.5 3.6 3.7
|
||||||
*/
|
*/
|
||||||
mesh.Vertex.prototype.toString = function() {
|
geo.Vertex.prototype.toString = function() {
|
||||||
return 'v ' + this.x + ' ' + this.y + ' ' + this.z;
|
return 'v ' + this.x + ' ' + this.y + ' ' + this.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represent a 3D normal
|
* Represent a 3D normal
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
* @augments mesh.Vertex
|
* @augments geo.Vertex
|
||||||
*/
|
*/
|
||||||
mesh.Normal = function() {
|
geo.Normal = function() {
|
||||||
mesh.Vertex.apply(this, arguments);
|
geo.Vertex.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.Normal.prototype = Object.create(mesh.Vertex.prototype);
|
geo.Normal.prototype = Object.create(geo.Vertex.prototype);
|
||||||
mesh.Normal.prototype.constructor = mesh.Normal;
|
geo.Normal.prototype.constructor = geo.Normal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives a list representation of the normal
|
* Gives a list representation of the normal
|
||||||
* @returns {Array} An array representing the normal
|
* @returns {Array} An array representing the normal
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var normal = new mesh.Normal('vn 3.5 3.6 3.7');
|
* var normal = new geo.Normal('vn 3.5 3.6 3.7');
|
||||||
* normal.index = 5;
|
* normal.index = 5;
|
||||||
* console.log(normal.toList()); // Prints ['vn', 5, 3.5, 3.6, 3.7]
|
* console.log(normal.toList()); // Prints ['vn', 5, 3.5, 3.6, 3.7]
|
||||||
*/
|
*/
|
||||||
mesh.Normal.prototype.toList = function() {
|
geo.Normal.prototype.toList = function() {
|
||||||
var superObject = mesh.Vertex.prototype.toList.call(this);
|
var superObject = geo.Vertex.prototype.toList.call(this);
|
||||||
superObject[0] = 'vn';
|
superObject[0] = 'vn';
|
||||||
return superObject;
|
return superObject;
|
||||||
}
|
}
|
||||||
|
@ -208,11 +203,11 @@ mesh.Normal.prototype.toList = function() {
|
||||||
* @returns {string} A string representing the normal
|
* @returns {string} A string representing the normal
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var normal = new mesh.Normal('vn 3.5 3.6 3.7');
|
* var normal = new geo.Normal('vn 3.5 3.6 3.7');
|
||||||
* console.log(normal.toString()); // Prints vn 3.5 3.6 3.7
|
* console.log(normal.toString()); // Prints vn 3.5 3.6 3.7
|
||||||
*/
|
*/
|
||||||
mesh.Normal.prototype.toString = function() {
|
geo.Normal.prototype.toString = function() {
|
||||||
var superObject = mesh.Vertex.prototype.toString.call(this);
|
var superObject = geo.Vertex.prototype.toString.call(this);
|
||||||
superObject.replace('v', 'vn');
|
superObject.replace('v', 'vn');
|
||||||
return superObject;
|
return superObject;
|
||||||
}
|
}
|
||||||
|
@ -220,9 +215,9 @@ mesh.Normal.prototype.toString = function() {
|
||||||
/**
|
/**
|
||||||
* Represent a texture coordinate element
|
* Represent a texture coordinate element
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
mesh.TexCoord = function() {
|
geo.TexCoord = function() {
|
||||||
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
||||||
var split = arguments[0].replace(/\s+/g, " ").split(' ');
|
var split = arguments[0].replace(/\s+/g, " ").split(' ');
|
||||||
|
|
||||||
|
@ -251,11 +246,11 @@ mesh.TexCoord = function() {
|
||||||
* @returns {Array} An array representing the texture coordinate
|
* @returns {Array} An array representing the texture coordinate
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var texCoord = new mesh.TexCoord('vt 3.5 3.6');
|
* var texCoord = new geo.TexCoord('vt 3.5 3.6');
|
||||||
* texture coordinate.index = 5;
|
* texture coordinate.index = 5;
|
||||||
* console.log(texture coordinate.toList()); // Prints ['vt', 5, 3.5, 3.6]
|
* console.log(texture coordinate.toList()); // Prints ['vt', 5, 3.5, 3.6]
|
||||||
*/
|
*/
|
||||||
mesh.TexCoord.prototype.toList = function() {
|
geo.TexCoord.prototype.toList = function() {
|
||||||
return ['vt', this.index, this.x, this.y];
|
return ['vt', this.index, this.x, this.y];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,10 +259,10 @@ mesh.TexCoord.prototype.toList = function() {
|
||||||
* @returns {string} A string representing the texture coordinate
|
* @returns {string} A string representing the texture coordinate
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var texCoord = new mesh.TexCoord('vt 3.5 3.6');
|
* var texCoord = new geo.TexCoord('vt 3.5 3.6');
|
||||||
* console.log(texCoord.toString()); // Prints vt 3.5 3.6
|
* console.log(texCoord.toString()); // Prints vt 3.5 3.6
|
||||||
*/
|
*/
|
||||||
mesh.TexCoord.prototype.toString = function() {
|
geo.TexCoord.prototype.toString = function() {
|
||||||
return 'vt ' + this.x + ' ' + this.y;
|
return 'vt ' + this.x + ' ' + this.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,9 +270,9 @@ mesh.TexCoord.prototype.toString = function() {
|
||||||
/**
|
/**
|
||||||
* Represents a face
|
* Represents a face
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
mesh.Face = function() {
|
geo.Face = function() {
|
||||||
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
if (typeof arguments[0] === 'string' || arguments[0] instanceof String) {
|
||||||
if (arguments[0].indexOf('/') === -1) {
|
if (arguments[0].indexOf('/') === -1) {
|
||||||
// No / : easy win : "f 1 2 3" or "f 1 2 3 4"
|
// No / : easy win : "f 1 2 3" or "f 1 2 3 4"
|
||||||
|
@ -379,12 +374,12 @@ var parseFace = function(arg) {
|
||||||
|
|
||||||
// Face3
|
// Face3
|
||||||
if (split.length >= 4) {
|
if (split.length >= 4) {
|
||||||
ret.push(new mesh.Face(arg));
|
ret.push(new geo.Face(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Face3 == 2 * Face3
|
// Face3 == 2 * Face3
|
||||||
if (split.length >= 5) {
|
if (split.length >= 5) {
|
||||||
ret.push(new mesh.Face(
|
ret.push(new geo.Face(
|
||||||
[
|
[
|
||||||
split[0],
|
split[0],
|
||||||
split[1],
|
split[1],
|
||||||
|
@ -401,7 +396,7 @@ var parseFace = function(arg) {
|
||||||
* Returns the max index of the vertices of the face
|
* Returns the max index of the vertices of the face
|
||||||
* @returns {Number} the max index of the vertices
|
* @returns {Number} the max index of the vertices
|
||||||
*/
|
*/
|
||||||
mesh.Face.prototype.max = function() {
|
geo.Face.prototype.max = function() {
|
||||||
if (this.d !== undefined) {
|
if (this.d !== undefined) {
|
||||||
return Math.max(this.a, this.b, this.c, this.d);
|
return Math.max(this.a, this.b, this.c, this.d);
|
||||||
} else {
|
} else {
|
||||||
|
@ -413,7 +408,7 @@ mesh.Face.prototype.max = function() {
|
||||||
* Returns the max index of the texture coordinates of the face
|
* Returns the max index of the texture coordinates of the face
|
||||||
* @returns {Number} the max index of the texture coordinates
|
* @returns {Number} the max index of the texture coordinates
|
||||||
*/
|
*/
|
||||||
mesh.Face.prototype.maxTexture = function() {
|
geo.Face.prototype.maxTexture = function() {
|
||||||
if (this.dTexture) {
|
if (this.dTexture) {
|
||||||
return Math.max(this.aTexture, this.bTexture, this.cTexture, this.dTexture);
|
return Math.max(this.aTexture, this.bTexture, this.cTexture, this.dTexture);
|
||||||
} else {
|
} else {
|
||||||
|
@ -433,11 +428,11 @@ mesh.Face.prototype.maxTexture = function() {
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var face = new mesh.Face('f 1/2/3 4/5/6 7/8/9');
|
* var face = new geo.Face('f 1/2/3 4/5/6 7/8/9');
|
||||||
* texture coordinate.index = 5;
|
* texture coordinate.index = 5;
|
||||||
* console.log(texture coordinate.toList()); // Prints ['f', 5, [1,4,7], [2,5,8], [3,6,9]]
|
* console.log(texture coordinate.toList()); // Prints ['f', 5, [1,4,7], [2,5,8], [3,6,9]]
|
||||||
*/
|
*/
|
||||||
mesh.Face.prototype.toList = function() {
|
geo.Face.prototype.toList = function() {
|
||||||
var l = ['f', this.index, this.meshIndex,
|
var l = ['f', this.index, this.meshIndex,
|
||||||
[this.a, this.b, this.c ],
|
[this.a, this.b, this.c ],
|
||||||
isNaN(this.aTexture) ? [] : [this.aTexture, this.bTexture, this.cTexture],
|
isNaN(this.aTexture) ? [] : [this.aTexture, this.bTexture, this.cTexture],
|
||||||
|
@ -464,10 +459,10 @@ mesh.Face.prototype.toList = function() {
|
||||||
* @returns {string} A string representing the face
|
* @returns {string} A string representing the face
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* var face = new mesh.Face('f 3 5 6');
|
* var face = new geo.Face('f 3 5 6');
|
||||||
* console.log(face.toString()); // Prints f 3 5 6
|
* console.log(face.toString()); // Prints f 3 5 6
|
||||||
*/
|
*/
|
||||||
mesh.Face.prototype.toString = function() {
|
geo.Face.prototype.toString = function() {
|
||||||
return 'f ' + this.a + ' ' + this.b + ' ' + this.c + (this.d !== undefined ? ' ' + this.d : '');
|
return 'f ' + this.a + ' ' + this.b + ' ' + this.c + (this.d !== undefined ? ' ' + this.d : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,9 +470,9 @@ mesh.Face.prototype.toString = function() {
|
||||||
* Represents a material name
|
* Represents a material name
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {string} line the string representing the material
|
* @param {string} line the string representing the material
|
||||||
* @memberOf mesh
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
mesh.Material = function() {
|
geo.Material = function() {
|
||||||
var split = arguments[0].replace(/\s+/g, ' ').trim().split(' ');
|
var split = arguments[0].replace(/\s+/g, ' ').trim().split(' ');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -491,7 +486,7 @@ mesh.Material = function() {
|
||||||
* Gives a string representation of the material
|
* Gives a string representation of the material
|
||||||
* @returns {string} obj representation of usemtl
|
* @returns {string} obj representation of usemtl
|
||||||
*/
|
*/
|
||||||
mesh.Material.prototype.toString = function() {
|
geo.Material.prototype.toString = function() {
|
||||||
return 'usemtl ' + this.name;
|
return 'usemtl ' + this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,11 +494,10 @@ mesh.Material.prototype.toString = function() {
|
||||||
* Gives a list representation of the material
|
* Gives a list representation of the material
|
||||||
* @returns {array} an array representing the material
|
* @returns {array} an array representing the material
|
||||||
* @example
|
* @example
|
||||||
* var material = new mesh.Material('usemtl MyMaterial');
|
* var material = new geo.Material('usemtl MyMaterial');
|
||||||
* console.log(material.toList()); // Logs ['u', 'MyMaterial']
|
* console.log(material.toList()); // Logs ['u', 'MyMaterial']
|
||||||
*/
|
*/
|
||||||
mesh.Material.prototype.toList = function() {
|
geo.Material.prototype.toList = function() {
|
||||||
return ['u', this.name];
|
return ['u', this.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = mesh;
|
|
||||||
|
|
|
@ -1,46 +1,38 @@
|
||||||
var fs = require('fs');
|
|
||||||
var mesh = require('./Mesh.js');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @namespace
|
* Represents a mesh. All meshes are loaded once in geo.availableMesh to avoid
|
||||||
*/
|
|
||||||
var cont = {};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a mesh. All meshes are loaded once in cont.availableMesh to avoid
|
|
||||||
* loading at each mesh request
|
* loading at each mesh request
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberOf cont
|
* @memberOf geo
|
||||||
*/
|
*/
|
||||||
cont.MeshContainer = function(path) {
|
geo.MeshContainer = function(path) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of each part of the mesh
|
* array of each part of the mesh
|
||||||
* @type {mesh.Mesh[]}
|
* @type {geo.Mesh[]}
|
||||||
*/
|
*/
|
||||||
this.meshes = [];
|
this.meshes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of the vertices of the meshes (all merged)
|
* array of the vertices of the meshes (all merged)
|
||||||
* @type {mesh.Vertex[]}
|
* @type {geo.Vertex[]}
|
||||||
*/
|
*/
|
||||||
this.vertices = [];
|
this.vertices = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of the faces of the meshes (all merged)
|
* array of the faces of the meshes (all merged)
|
||||||
* @type {mesh.Face[]}
|
* @type {geo.Face[]}
|
||||||
*/
|
*/
|
||||||
this.faces = [];
|
this.faces = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of the normals of the meshes (all merged)
|
* array of the normals of the meshes (all merged)
|
||||||
* @type {mesh.Normal[]}
|
* @type {geo.Normal[]}
|
||||||
*/
|
*/
|
||||||
this.normals = [];
|
this.normals = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of the texture coordinates (all merged)
|
* array of the texture coordinates (all merged)
|
||||||
* @type {mesh.TexCoord[]}
|
* @type {geo.TexCoord[]}
|
||||||
*/
|
*/
|
||||||
this.texCoords = [];
|
this.texCoords = [];
|
||||||
|
|
||||||
|
@ -56,7 +48,7 @@ cont.MeshContainer = function(path) {
|
||||||
* Loads a obj file
|
* Loads a obj file
|
||||||
* @param {string} path the path to the file
|
* @param {string} path the path to the file
|
||||||
*/
|
*/
|
||||||
cont.MeshContainer.prototype.loadFromFile = function(path) {
|
geo.MeshContainer.prototype.loadFromFile = function(path) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var data = fs.readFileSync(path, {encoding: 'utf-8'});
|
var data = fs.readFileSync(path, {encoding: 'utf-8'});
|
||||||
|
@ -76,13 +68,13 @@ cont.MeshContainer.prototype.loadFromFile = function(path) {
|
||||||
if (line[1] === 't') {
|
if (line[1] === 't') {
|
||||||
|
|
||||||
// Texture coord
|
// Texture coord
|
||||||
var texCoord = new mesh.TexCoord(line);
|
var texCoord = new geo.TexCoord(line);
|
||||||
texCoord.index = self.texCoords.length;
|
texCoord.index = self.texCoords.length;
|
||||||
self.texCoords.push(texCoord);
|
self.texCoords.push(texCoord);
|
||||||
|
|
||||||
} else if (line[1] === 'n') {
|
} else if (line[1] === 'n') {
|
||||||
|
|
||||||
var normal = new mesh.Normal(line);
|
var normal = new geo.Normal(line);
|
||||||
normal.index = self.normals.length;
|
normal.index = self.normals.length;
|
||||||
self.normals.push(normal);
|
self.normals.push(normal);
|
||||||
|
|
||||||
|
@ -92,12 +84,12 @@ cont.MeshContainer.prototype.loadFromFile = function(path) {
|
||||||
// if (currentMesh === undefined) {
|
// if (currentMesh === undefined) {
|
||||||
|
|
||||||
// // Chances are that we won't use any material in this case
|
// // Chances are that we won't use any material in this case
|
||||||
// currentMesh = new mesh.Mesh();
|
// currentMesh = new geo.Mesh();
|
||||||
// self.meshes.push(currentMesh);
|
// self.meshes.push(currentMesh);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
var vertex = new mesh.Vertex(line);
|
var vertex = new geo.Vertex(line);
|
||||||
vertex.index = self.vertices.length;
|
vertex.index = self.vertices.length;
|
||||||
self.vertices.push(vertex);
|
self.vertices.push(vertex);
|
||||||
|
|
||||||
|
@ -107,7 +99,7 @@ cont.MeshContainer.prototype.loadFromFile = function(path) {
|
||||||
|
|
||||||
// Create mesh if it doesn't exist
|
// Create mesh if it doesn't exist
|
||||||
if (currentMesh === undefined) {
|
if (currentMesh === undefined) {
|
||||||
currentMesh = new mesh.Mesh();
|
currentMesh = new geo.Mesh();
|
||||||
self.meshes.push(currentMesh);
|
self.meshes.push(currentMesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +124,9 @@ cont.MeshContainer.prototype.loadFromFile = function(path) {
|
||||||
// If a current mesh exists, finish it
|
// If a current mesh exists, finish it
|
||||||
|
|
||||||
// Create a new mesh
|
// Create a new mesh
|
||||||
currentMesh = new mesh.Mesh();
|
currentMesh = new geo.Mesh();
|
||||||
self.meshes.push(currentMesh);
|
self.meshes.push(currentMesh);
|
||||||
currentMesh.material = (new mesh.Material(line)).name;
|
currentMesh.material = (new geo.Material(line)).name;
|
||||||
// console.log(currentMesh.material);
|
// console.log(currentMesh.material);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -157,13 +149,11 @@ for (var i = 1; i < 26; i++) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cont.availableMeshes = {};
|
geo.availableMeshes = {};
|
||||||
|
|
||||||
for (var i = 0; i < availableMeshNames.length; i++) {
|
for (var i = 0; i < availableMeshNames.length; i++) {
|
||||||
|
|
||||||
var name = availableMeshNames[i];
|
var name = availableMeshNames[i];
|
||||||
cont.availableMeshes[name] = new cont.MeshContainer(name.substring(1, name.length));
|
geo.availableMeshes[name] = new geo.MeshContainer(name.substring(1, name.length));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = cont;
|
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
var fs = require('fs');
|
|
||||||
var mesh = require('./Mesh.js');
|
|
||||||
var cont = require('./MeshContainer.js');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @namespace
|
|
||||||
*/
|
|
||||||
var geo = {};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -58,7 +49,13 @@ geo.MeshStreamer = function(path) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* array of array telling if the jth face of the ith mesh has already been sent
|
* array of array telling if the jth face of the ith mesh has already been sent
|
||||||
* @type{Boolean[][]}
|
*
|
||||||
|
* For each mesh, there is an object containing
|
||||||
|
* <ul>
|
||||||
|
* <li>`counter` : the number of faces currently sent</li>
|
||||||
|
* <li>`array` : an array boolean telling if the ith face has already been sent</li>
|
||||||
|
* </ul>
|
||||||
|
* @type {Object[]}
|
||||||
*/
|
*/
|
||||||
this.meshFaces = [];
|
this.meshFaces = [];
|
||||||
|
|
||||||
|
@ -94,7 +91,7 @@ geo.MeshStreamer = function(path) {
|
||||||
|
|
||||||
if (path !== undefined) {
|
if (path !== undefined) {
|
||||||
|
|
||||||
this.mesh = cont.availableMeshes[path];
|
this.mesh = geo.availableMeshes[path];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +186,7 @@ geo.MeshStreamer.prototype.start = function(socket) {
|
||||||
|
|
||||||
socket.on('request', function(path) {
|
socket.on('request', function(path) {
|
||||||
|
|
||||||
self.mesh = cont.availableMeshes[path];
|
self.mesh = geo.availableMeshes[path];
|
||||||
|
|
||||||
self.meshFaces = new Array(self.mesh.meshes.length);
|
self.meshFaces = new Array(self.mesh.meshes.length);
|
||||||
|
|
||||||
|
@ -540,5 +537,3 @@ geo.MeshStreamer.prototype.isFinished = function(i) {
|
||||||
return this.meshFaces[i].counter === this.meshFaces[i].array.length;
|
return this.meshFaces[i].counter === this.meshFaces[i].array.length;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = geo;
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ OPT=--compilation_level SIMPLE_OPTIMIZATIONS
|
||||||
ifeq ($(TYPE),RELEASE)
|
ifeq ($(TYPE),RELEASE)
|
||||||
CLOSURE=java -jar /usr/share/java/closure-compiler/closure-compiler.jar
|
CLOSURE=java -jar /usr/share/java/closure-compiler/closure-compiler.jar
|
||||||
else
|
else
|
||||||
CLOSURE=./compiler.sh
|
CLOSURE=../utils/compiler.sh
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: List ListTest Socket Three Stats ThreeTools Bouncing Multisphere StreamingSimulator PrototypeTools PrototypeReplay PrototypeInteractive Tutorial
|
all: List ListTest Socket Three Stats ThreeTools Bouncing Multisphere StreamingSimulator PrototypeTools PrototypeReplay PrototypeInteractive Tutorial
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var geo = require('./geo/MeshStreamer.js');
|
var geo = require('./lib/geo.min.js');
|
||||||
|
|
||||||
module.exports = function(io) {
|
module.exports = function(io) {
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
|
|
Loading…
Reference in New Issue