2015-06-15 17:04:19 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var mesh = require('./Mesh.js');
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
var geo = {};
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2015-06-18 16:30:37 +02:00
|
|
|
function bisect(items, x, lo, hi) {
|
|
|
|
var mid;
|
|
|
|
if (typeof(lo) == 'undefined') lo = 0;
|
|
|
|
if (typeof(hi) == 'undefined') hi = items.length;
|
|
|
|
while (lo < hi) {
|
|
|
|
mid = Math.floor((lo + hi) / 2);
|
|
|
|
if (x < items[mid]) hi = mid;
|
|
|
|
else lo = mid + 1;
|
|
|
|
}
|
|
|
|
return lo;
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2015-06-18 16:30:37 +02:00
|
|
|
function insort(items, x) {
|
|
|
|
items.splice(bisect(items, x), 0, x);
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2015-06-18 16:30:37 +02:00
|
|
|
function partialSort(items, k, comparator) {
|
|
|
|
var smallest = items.slice(0, k).sort(),
|
|
|
|
max = smallest[k-1];
|
|
|
|
|
|
|
|
for (var i = k, len = items.length; i < len; ++i) {
|
|
|
|
var item = items[i];
|
|
|
|
var cond = comparator === undefined ? item < max : comparator(item, max) < 0;
|
|
|
|
if (cond) {
|
|
|
|
insort(smallest, item);
|
|
|
|
smallest.length = k;
|
|
|
|
max = smallest[k-1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return smallest;
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* A class that streams easily a mesh via socket.io
|
|
|
|
* @memberOf geo
|
|
|
|
* @constructor
|
|
|
|
* @param {string} path to the mesh
|
|
|
|
* @param {function} callback to execute when the mesh streamer is loaded
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
geo.MeshStreamer = function(path, callback) {
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* array of each part of the mesh
|
|
|
|
* @type {mesh.Mesh[]}
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.meshes = [];
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* array of the vertices of the meshes (all merged)
|
|
|
|
* @type {mesh.Vertex[]}
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.vertices = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* array of the faces of the meshes (all merged)
|
|
|
|
* @type {mesh.Face[]}
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.faces = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* array of the normals of the meshes (all merged)
|
|
|
|
* @type {mesh.Normal[]}
|
|
|
|
*/
|
2015-06-16 12:05:29 +02:00
|
|
|
this.normals = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* array of the texture coordinates (all merged)
|
|
|
|
* @type {mesh.TexCoord[]}
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.texCoords = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* array of the faces in a nice order for sending
|
|
|
|
* @type {mesh.Face[]}
|
|
|
|
*/
|
2015-06-18 16:30:37 +02:00
|
|
|
this.orderedFaces = [];
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Number of element to send by packet
|
|
|
|
* @type {Number}
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.chunk = 1000;
|
|
|
|
|
|
|
|
if (path !== undefined) {
|
|
|
|
var self = this;
|
|
|
|
this.loadFromFile(path, function() {
|
|
|
|
if (typeof callback === 'function')
|
|
|
|
callback();
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Compute a function that can compare two faces
|
|
|
|
* @param {Camera} camera a camera seeing or not face
|
|
|
|
* @returns the function that compares two faces : the higher face is the most interesting for the camera
|
|
|
|
*/
|
2015-06-18 16:30:37 +02:00
|
|
|
geo.MeshStreamer.prototype.faceComparator = function(camera) {
|
|
|
|
|
2015-06-18 16:58:07 +02:00
|
|
|
var self = this;
|
|
|
|
|
2015-06-18 16:30:37 +02:00
|
|
|
var direction = {
|
|
|
|
x: camera.target.x - camera.position.x,
|
|
|
|
y: camera.target.y - camera.position.y,
|
|
|
|
z: camera.target.z - camera.position.z
|
|
|
|
};
|
|
|
|
|
|
|
|
var norm = Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
|
|
|
|
|
|
|
|
direction.x /= norm;
|
|
|
|
direction.y /= norm;
|
|
|
|
direction.z /= norm;
|
|
|
|
|
|
|
|
return function(face1, face2) {
|
|
|
|
|
|
|
|
var center1 = {
|
|
|
|
x: (self.vertices[face1.a].x + self.vertices[face1.b].x + self.vertices[face1.b].x) / 3,
|
|
|
|
y: (self.vertices[face1.a].y + self.vertices[face1.b].y + self.vertices[face1.b].y) / 3,
|
|
|
|
z: (self.vertices[face1.a].z + self.vertices[face1.b].z + self.vertices[face1.b].z) / 3
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var dir1 = {
|
|
|
|
x: center1.x - camera.position.x,
|
|
|
|
y: center1.y - camera.position.y,
|
|
|
|
z: center1.z - camera.position.z
|
|
|
|
};
|
|
|
|
|
|
|
|
var norm1 = Math.sqrt(dir1.x * dir1.x + dir1.y * dir1.y + dir1.z + dir1.z);
|
|
|
|
|
|
|
|
dir1.x /= norm1;
|
|
|
|
dir1.y /= norm1;
|
|
|
|
dir1.z /= norm1;
|
|
|
|
|
|
|
|
var dot1 = direction.x * dir1.x + direction.y * dir1.y + direction.z * dir1.z;
|
|
|
|
|
|
|
|
var center2 = {
|
|
|
|
x: (self.vertices[face2.a].x + self.vertices[face2.b].x + self.vertices[face2.b].x) / 3,
|
|
|
|
y: (self.vertices[face2.a].y + self.vertices[face2.b].y + self.vertices[face2.b].y) / 3,
|
|
|
|
z: (self.vertices[face2.a].z + self.vertices[face2.b].z + self.vertices[face2.b].z) / 3
|
|
|
|
}
|
|
|
|
|
|
|
|
var dir2 = {
|
|
|
|
x: center2.x - camera.position.x,
|
|
|
|
y: center2.y - camera.position.y,
|
|
|
|
z: center2.z - camera.position.z
|
|
|
|
};
|
|
|
|
|
|
|
|
var norm2 = Math.sqrt(dir2.x * dir2.x + dir2.y * dir2.y + dir2.z + dir2.z);
|
|
|
|
|
|
|
|
dir2.x /= norm2;
|
|
|
|
dir2.y /= norm2;
|
|
|
|
dir2.z /= norm2;
|
|
|
|
|
|
|
|
var dot2 = direction.x * dir2.x + direction.y * dir2.y + direction.z * dir2.z;
|
|
|
|
|
|
|
|
// Decreasing order
|
|
|
|
if (dot1 > dot2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (dot1 < dot2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Loads a obj file
|
|
|
|
* @param {string} path the path to the file
|
|
|
|
* @param {function} callback the callback to call when the mesh is loaded
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
geo.MeshStreamer.prototype.loadFromFile = function(path, callback) {
|
|
|
|
var self = this;
|
|
|
|
fs.readFile(path, function(err, data) {
|
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
var oldTime = Date.now();
|
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
var currentMesh;
|
|
|
|
|
|
|
|
// Get lines from file
|
|
|
|
var lines = data.toString('utf-8').split("\n");
|
|
|
|
|
|
|
|
// For each line
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
|
|
|
|
var line = lines[i];
|
|
|
|
|
|
|
|
if (line[0] === 'v') {
|
|
|
|
|
|
|
|
if (line[1] === 't') {
|
|
|
|
|
|
|
|
// Texture coord
|
2015-06-16 12:05:29 +02:00
|
|
|
var texCoord = new mesh.TexCoord(line);
|
|
|
|
texCoord.index = self.texCoords.length;
|
|
|
|
self.texCoords.push(texCoord);
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
} else if (line[1] === 'n') {
|
|
|
|
|
2015-06-16 12:05:29 +02:00
|
|
|
var normal = new mesh.Normal(line);
|
|
|
|
normal.index = self.normals.length;
|
|
|
|
self.normals.push(normal);
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Just a simple vertex
|
2015-06-16 12:05:29 +02:00
|
|
|
// if (currentMesh === undefined) {
|
|
|
|
|
|
|
|
// // Chances are that we won't use any material in this case
|
|
|
|
// currentMesh = new mesh.Mesh();
|
|
|
|
// self.meshes.push(currentMesh);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
var vertex = new mesh.Vertex(line);
|
2015-06-15 17:04:19 +02:00
|
|
|
vertex.index = self.vertices.length;
|
|
|
|
self.vertices.push(vertex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (line[0] === 'f') {
|
|
|
|
|
2015-06-16 12:05:29 +02:00
|
|
|
// Create mesh if it doesn't exist
|
|
|
|
if (currentMesh === undefined) {
|
|
|
|
currentMesh = new mesh.Mesh();
|
|
|
|
self.meshes.push(currentMesh);
|
|
|
|
}
|
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
// Create faces (two if Face4)
|
|
|
|
var faces = currentMesh.addFaces(line);
|
|
|
|
|
2015-06-18 14:46:09 +02:00
|
|
|
faces[0].index = self.faces.length;
|
2015-06-18 11:46:24 +02:00
|
|
|
faces[0].meshIndex = self.meshes.length - 1;
|
2015-06-15 17:04:19 +02:00
|
|
|
self.faces.push(faces[0]);
|
2015-06-18 16:30:37 +02:00
|
|
|
self.orderedFaces.push(faces[0]);
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
if (faces.length === 2) {
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-18 14:46:09 +02:00
|
|
|
faces[1].index = self.faces.length;
|
2015-06-18 11:46:24 +02:00
|
|
|
faces[1].meshIndex = self.meshes.length - 1;
|
2015-06-15 17:04:19 +02:00
|
|
|
self.faces.push(faces[1]);
|
2015-06-18 16:30:37 +02:00
|
|
|
self.orderedFaces.push(faces[1]);
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (line[0] === 'u') {
|
|
|
|
|
|
|
|
// usemtl
|
2015-06-16 12:05:29 +02:00
|
|
|
// If a current mesh exists, finish it
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
// Create a new mesh
|
|
|
|
currentMesh = new mesh.Mesh();
|
|
|
|
self.meshes.push(currentMesh);
|
2015-06-16 12:05:29 +02:00
|
|
|
currentMesh.material = (new mesh.Material(line)).name;
|
|
|
|
// console.log(currentMesh.material);
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback();
|
|
|
|
}
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
console.log(Date.now() - oldTime);
|
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Initialize the socket.io callback
|
|
|
|
* @param {socket} socket the socket to initialize
|
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
geo.MeshStreamer.prototype.start = function(socket) {
|
|
|
|
|
2015-06-16 16:35:43 +02:00
|
|
|
this.meshIndex = 0;
|
2015-06-18 11:46:24 +02:00
|
|
|
this.socket = socket;
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
socket.on('request', function(path) {
|
|
|
|
console.log('Asking for ' + path);
|
|
|
|
|
|
|
|
var regex = /.*\.\..*/;
|
2015-06-23 14:05:40 +02:00
|
|
|
var filePath = path.substring(1, path.length);
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-23 14:05:40 +02:00
|
|
|
if (regex.test(filePath)) {
|
2015-06-15 17:04:19 +02:00
|
|
|
socket.emit('refused');
|
|
|
|
socket.disconnect();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-23 14:05:40 +02:00
|
|
|
self.loadFromFile(filePath, function() {
|
2015-06-15 17:04:19 +02:00
|
|
|
socket.emit('ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-06-18 16:58:07 +02:00
|
|
|
socket.on('materials', function() {
|
|
|
|
|
|
|
|
var data = self.nextMaterials();
|
|
|
|
|
|
|
|
socket.emit('elements', data);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
socket.on('next', function(camera) {
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
// Send next elements
|
2015-06-18 11:46:24 +02:00
|
|
|
var next = self.nextElements(camera);
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
socket.emit('elements', next.data);
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
if (next.finished) {
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
socket.disconnect();
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
}
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
});
|
|
|
|
}
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Prepare the array of materials
|
|
|
|
* @return array the array to send with all materials of the current mesh
|
|
|
|
*/
|
2015-06-18 16:58:07 +02:00
|
|
|
geo.MeshStreamer.prototype.nextMaterials = function() {
|
|
|
|
|
|
|
|
var data = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < this.meshes.length; i++) {
|
|
|
|
|
|
|
|
var currentMesh = this.meshes[i];
|
|
|
|
|
|
|
|
// Send usemtl
|
|
|
|
data.push([
|
|
|
|
'u',
|
|
|
|
currentMesh.material,
|
|
|
|
currentMesh.vertices.length,
|
|
|
|
currentMesh.faces.length,
|
|
|
|
this.texCoords.length > 0,
|
|
|
|
this.normals.length > 0
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
|
|
|
* Prepare the next elements
|
|
|
|
* @param {camera} _camera a camera that can be usefull to do smart streaming (stream
|
|
|
|
* only interesting parts according to the camera
|
|
|
|
* @returns {array} an array of elements ready to send
|
|
|
|
*/
|
2015-06-18 11:46:24 +02:00
|
|
|
geo.MeshStreamer.prototype.nextElements = function(_camera) {
|
|
|
|
|
|
|
|
// Prepare camera (and scale to model)
|
2015-06-18 15:03:06 +02:00
|
|
|
var camera = null;
|
|
|
|
|
|
|
|
if (_camera !== null) {
|
|
|
|
|
|
|
|
var camera = {
|
|
|
|
position: {
|
|
|
|
x: _camera[0],
|
|
|
|
y: _camera[1],
|
|
|
|
z: _camera[2]
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
x: _camera[3],
|
|
|
|
y: _camera[4],
|
|
|
|
z: _camera[5]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute camera direction
|
|
|
|
var direction = {
|
|
|
|
x: camera.target.x - camera.position.x,
|
|
|
|
y: camera.target.y - camera.position.y,
|
|
|
|
z: camera.target.z - camera.position.z
|
2015-06-18 11:46:24 +02:00
|
|
|
}
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
}
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-18 14:46:09 +02:00
|
|
|
var sent = 0;
|
2015-06-18 11:46:24 +02:00
|
|
|
var data = [];
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-18 16:58:07 +02:00
|
|
|
// Sort faces
|
2015-06-18 11:46:24 +02:00
|
|
|
var mightBeCompletetlyFinished = true;
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var currentMesh = this.meshes[meshIndex];
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (currentMesh.isFinished()) {
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
continue;
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
} else {
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
mightBeCompletetlyFinished = false;
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-18 11:46:24 +02:00
|
|
|
}
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
for (var faceIndex = 0; faceIndex < currentMesh.faces.length; faceIndex++) {
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var currentFace = currentMesh.faces[faceIndex];
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (currentFace.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
continue;
|
2015-06-16 12:05:29 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var vertex1 = this.vertices[currentFace.a];
|
|
|
|
var vertex2 = this.vertices[currentFace.b];
|
|
|
|
var vertex3 = this.vertices[currentFace.c];
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (camera !== null) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var v1 = {
|
|
|
|
x: vertex1.x - camera.position.x,
|
|
|
|
y: vertex1.y - camera.position.y,
|
|
|
|
z: vertex1.z - camera.position.z
|
|
|
|
};
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var v2 = {
|
|
|
|
x: vertex2.x - camera.position.x,
|
|
|
|
y: vertex2.y - camera.position.y,
|
|
|
|
z: vertex2.z - camera.position.z
|
|
|
|
};
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var v3 = {
|
|
|
|
x: vertex3.x - camera.position.x,
|
|
|
|
y: vertex3.y - camera.position.y,
|
|
|
|
z: vertex3.z - camera.position.z
|
|
|
|
};
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (
|
|
|
|
direction.x * v1.x + direction.y * v1.y + direction.z * v1.z < 0 &&
|
|
|
|
direction.x * v2.x + direction.y * v2.y + direction.z * v2.z < 0 &&
|
2015-06-23 15:31:23 +02:00
|
|
|
direction.x * v3.x + direction.y * v3.y + direction.z * v3.z < 0
|
2015-06-19 11:24:37 +02:00
|
|
|
) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
continue;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (!vertex1.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex1.toList());
|
|
|
|
vertex1.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (!vertex2.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex2.toList());
|
|
|
|
vertex2.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (!vertex3.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex3.toList());
|
|
|
|
vertex3.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var normal1 = this.normals[currentFace.aNormal];
|
|
|
|
var normal2 = this.normals[currentFace.bNormal];
|
|
|
|
var normal3 = this.normals[currentFace.cNormal];
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (normal1 !== undefined && !normal1.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal1.toList());
|
|
|
|
normal1.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (normal2 !== undefined && !normal2.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal2.toList());
|
|
|
|
normal2.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (normal3 !== undefined && !normal3.sent) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal3.toList());
|
|
|
|
normal3.sent = true;
|
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
var tex1 = this.texCoords[currentFace.aTexture];
|
|
|
|
var tex2 = this.texCoords[currentFace.bTexture];
|
|
|
|
var tex3 = this.texCoords[currentFace.cTexture];
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (tex1 !== undefined && !tex1.sent) {
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(tex1.toList());
|
|
|
|
tex1.sent = true;
|
|
|
|
sent++;
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (tex2 !== undefined && !tex2.sent) {
|
|
|
|
|
|
|
|
data.push(tex2.toList());
|
|
|
|
tex2.sent = true;
|
|
|
|
sent++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tex3 !== undefined && !tex3.sent) {
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(tex3.toList());
|
|
|
|
tex3.sent = true;
|
|
|
|
sent++;
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data.push(currentFace.toList());
|
|
|
|
currentFace.sent = true;
|
|
|
|
currentMesh.faceIndex++;
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
sent++;
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
if (sent > 500) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
return {data: data, finished: false};
|
|
|
|
|
|
|
|
}
|
2015-06-15 17:04:19 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {data: data, finished: mightBeCompletetlyFinished};
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = geo;
|