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
|
|
|
|
*/
|
2015-06-29 09:50:26 +02:00
|
|
|
geo.MeshStreamer = function(path) {
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-29 10:43:29 +02:00
|
|
|
/**
|
|
|
|
* array of array telling if the jth face of the ith mesh has already been sent
|
2015-06-29 15:41:18 +02:00
|
|
|
*
|
|
|
|
* 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[]}
|
2015-06-29 10:43:29 +02:00
|
|
|
*/
|
|
|
|
this.meshFaces = [];
|
|
|
|
|
2015-06-23 15:31:23 +02:00
|
|
|
/**
|
2015-06-29 09:50:26 +02:00
|
|
|
* array of booleans telling if the ith vertex has already been sent
|
|
|
|
* @type {Boolean[]}
|
2015-06-23 15:31:23 +02:00
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.vertices = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
2015-06-29 09:50:26 +02:00
|
|
|
* array of booleans telling if the ith face has already been sent
|
|
|
|
* @type {Boolean[]}
|
2015-06-23 15:31:23 +02:00
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.faces = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
2015-06-29 09:50:26 +02:00
|
|
|
* array of booleans telling if the ith normal has already been sent
|
|
|
|
* @type {Boolean[]}
|
2015-06-23 15:31:23 +02:00
|
|
|
*/
|
2015-06-16 12:05:29 +02:00
|
|
|
this.normals = [];
|
2015-06-23 15:31:23 +02:00
|
|
|
|
|
|
|
/**
|
2015-06-29 09:50:26 +02:00
|
|
|
* array of booleans telling if the ith texCoord has already been sent
|
|
|
|
* @type {Boolean[]}
|
2015-06-23 15:31:23 +02:00
|
|
|
*/
|
2015-06-15 17:04:19 +02:00
|
|
|
this.texCoords = [];
|
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) {
|
|
|
|
|
2015-06-29 15:41:18 +02:00
|
|
|
this.mesh = geo.availableMeshes[path];
|
2015-06-29 09:50:26 +02:00
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
}
|
2015-06-29 09:50:26 +02:00
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-15 17:04:19 +02:00
|
|
|
|
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
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-18 16:30:37 +02:00
|
|
|
|
|
|
|
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-07-01 10:14:15 +02:00
|
|
|
};
|
|
|
|
};
|
2015-06-18 16:30:37 +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) {
|
|
|
|
|
2015-06-29 15:41:18 +02:00
|
|
|
self.mesh = geo.availableMeshes[path];
|
2015-06-29 09:50:26 +02:00
|
|
|
|
2015-06-29 10:43:29 +02:00
|
|
|
self.meshFaces = new Array(self.mesh.meshes.length);
|
|
|
|
|
|
|
|
for (var i = 0; i < self.meshFaces.length; i++) {
|
|
|
|
|
|
|
|
self.meshFaces[i] = {
|
|
|
|
counter: 0,
|
|
|
|
array: new Array(self.mesh.meshes[i].faces.length)
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-15 17:04:19 +02:00
|
|
|
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-29 09:50:26 +02:00
|
|
|
socket.emit('ok');
|
2015-06-15 17:04:19 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
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-26 09:22:32 +02:00
|
|
|
if (next.data.length === 0) {
|
|
|
|
|
|
|
|
// If nothing, just serve stuff
|
|
|
|
var tmp = self.nextElements(camera, true);
|
|
|
|
next.data = tmp.data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-07-01 10:14:15 +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 = [];
|
|
|
|
|
2015-07-07 14:40:32 +02:00
|
|
|
data.push(['g', this.mesh.numberOfFaces]);
|
2015-07-07 11:47:21 +02:00
|
|
|
|
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
for (var i = 0; i < this.mesh.meshes.length; i++) {
|
2015-06-18 16:58:07 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
var currentMesh = this.mesh.meshes[i];
|
2015-06-18 16:58:07 +02:00
|
|
|
|
|
|
|
// Send usemtl
|
|
|
|
data.push([
|
|
|
|
'u',
|
|
|
|
currentMesh.material,
|
|
|
|
currentMesh.vertices.length,
|
|
|
|
currentMesh.faces.length,
|
2015-06-29 09:50:26 +02:00
|
|
|
this.mesh.texCoords.length > 0,
|
|
|
|
this.mesh.normals.length > 0
|
2015-06-18 16:58:07 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-18 16:58:07 +02:00
|
|
|
|
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-26 09:22:32 +02:00
|
|
|
geo.MeshStreamer.prototype.nextElements = function(_camera, force) {
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
var i;
|
|
|
|
|
2015-06-26 09:22:32 +02:00
|
|
|
if (force === undefined) {
|
|
|
|
|
|
|
|
force = false;
|
|
|
|
|
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
|
|
|
// Prepare camera (and scale to model)
|
2015-06-18 15:03:06 +02:00
|
|
|
var camera = null;
|
2015-06-26 09:22:32 +02:00
|
|
|
var planes = [];
|
|
|
|
var direction;
|
2015-06-18 15:03:06 +02:00
|
|
|
|
|
|
|
if (_camera !== null) {
|
|
|
|
|
2015-06-26 09:22:32 +02:00
|
|
|
camera = {
|
2015-06-18 15:03:06 +02:00
|
|
|
position: {
|
2015-06-26 09:22:32 +02:00
|
|
|
x: _camera[0][0],
|
|
|
|
y: _camera[0][1],
|
|
|
|
z: _camera[0][2]
|
2015-06-18 15:03:06 +02:00
|
|
|
},
|
|
|
|
target: {
|
2015-06-26 09:22:32 +02:00
|
|
|
x: _camera[1][0],
|
|
|
|
y: _camera[1][1],
|
|
|
|
z: _camera[1][2]
|
2015-06-18 15:03:06 +02:00
|
|
|
}
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-18 15:03:06 +02:00
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
for (i = 2; i < _camera.length; i++) {
|
2015-06-26 09:22:32 +02:00
|
|
|
|
|
|
|
planes.push({
|
|
|
|
normal: {
|
|
|
|
x: _camera[i][0],
|
|
|
|
y: _camera[i][1],
|
|
|
|
z: _camera[i][2]
|
|
|
|
},
|
|
|
|
constant: _camera[i][3]
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-18 15:03:06 +02:00
|
|
|
// Compute camera direction
|
2015-06-26 09:22:32 +02:00
|
|
|
direction = {
|
2015-06-18 15:03:06 +02:00
|
|
|
x: camera.target.x - camera.position.x,
|
|
|
|
y: camera.target.y - camera.position.y,
|
|
|
|
z: camera.target.z - camera.position.z
|
2015-07-01 10:14:15 +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-29 09:50:26 +02:00
|
|
|
for (var meshIndex = 0; meshIndex < this.mesh.meshes.length; meshIndex++) {
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
var currentMesh = this.mesh.meshes[meshIndex];
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-29 10:43:29 +02:00
|
|
|
if (this.isFinished(meshIndex)) {
|
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-29 10:43:29 +02:00
|
|
|
if (this.meshFaces[meshIndex].array[faceIndex] === true) {
|
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-29 09:50:26 +02:00
|
|
|
var vertex1 = this.mesh.vertices[currentFace.a];
|
|
|
|
var vertex2 = this.mesh.vertices[currentFace.b];
|
|
|
|
var vertex3 = this.mesh.vertices[currentFace.c];
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-26 09:22:32 +02:00
|
|
|
if (!force) {
|
|
|
|
|
2015-09-28 16:35:04 +02:00
|
|
|
var display = false;
|
|
|
|
var outcodes = [];
|
2015-06-26 09:22:32 +02:00
|
|
|
var exitToContinue = false;
|
|
|
|
threeVertices = [vertex1, vertex2, vertex3];
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
for (i = 0; i < threeVertices.length; i++) {
|
2015-06-26 09:22:32 +02:00
|
|
|
|
|
|
|
var vertex = threeVertices[i];
|
2015-09-28 16:35:04 +02:00
|
|
|
var currentOutcode = "";
|
2015-06-26 09:22:32 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-09-28 16:35:04 +02:00
|
|
|
// if (distance < 0) {
|
|
|
|
// exitToContinue = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
|
|
|
currentOutcode += distance > 0 ? '0' : '1';
|
2015-06-26 09:22:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:35:04 +02:00
|
|
|
outcodes.push(parseInt(currentOutcode,2));
|
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-09-28 16:35:04 +02:00
|
|
|
// 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
|
2015-06-26 09:22:32 +02:00
|
|
|
continue;
|
2015-09-28 16:35:04 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// part of the triangle is inside the viewing volume
|
|
|
|
}
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (!this.vertices[currentFace.a]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex1.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.vertices[currentFace.a] = true;
|
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
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (!this.vertices[currentFace.b]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex2.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.vertices[currentFace.b] = true;
|
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
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (!this.vertices[currentFace.c]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(vertex3.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.vertices[currentFace.c] = true;
|
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
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
var normal1 = this.mesh.normals[currentFace.aNormal];
|
|
|
|
var normal2 = this.mesh.normals[currentFace.bNormal];
|
|
|
|
var normal3 = this.mesh.normals[currentFace.cNormal];
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (normal1 !== undefined && !this.normals[currentFace.aNormal]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal1.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.normals[currentFace.aNormal] = true;
|
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
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (normal2 !== undefined && !this.normals[currentFace.bNormal]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal2.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.normals[currentFace.bNormal] = true;
|
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
|
|
|
}
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (normal3 !== undefined && !this.normals[currentFace.cNormal]) {
|
2015-06-18 11:46:24 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(normal3.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.normals[currentFace.cNormal] = true;
|
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
|
|
|
}
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
var tex1 = this.mesh.texCoords[currentFace.aTexture];
|
|
|
|
var tex2 = this.mesh.texCoords[currentFace.bTexture];
|
|
|
|
var tex3 = this.mesh.texCoords[currentFace.cTexture];
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (tex1 !== undefined && !this.texCoords[currentFace.aTexture]) {
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(tex1.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.texCoords[currentFace.aTexture] = true;
|
2015-06-19 11:24:37 +02:00
|
|
|
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-29 09:50:26 +02:00
|
|
|
if (tex2 !== undefined && !this.texCoords[currentFace.bTexture]) {
|
2015-06-19 11:24:37 +02:00
|
|
|
|
|
|
|
data.push(tex2.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.texCoords[currentFace.bTexture] = true;
|
2015-06-19 11:24:37 +02:00
|
|
|
sent++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-29 09:50:26 +02:00
|
|
|
if (tex3 !== undefined && !this.texCoords[currentFace.cTexture]) {
|
2015-06-16 16:35:43 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
data.push(tex3.toList());
|
2015-06-29 09:50:26 +02:00
|
|
|
this.texCoords[currentFace.cTexture] = true;
|
2015-06-19 11:24:37 +02:00
|
|
|
sent++;
|
2015-06-17 17:11:23 +02:00
|
|
|
|
2015-06-19 11:24:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
data.push(currentFace.toList());
|
2015-06-29 10:43:29 +02:00
|
|
|
// this.meshFaces[meshIndex] = this.meshFaces[meshIndex] || [];
|
|
|
|
this.meshFaces[meshIndex].array[faceIndex] = true;
|
|
|
|
this.meshFaces[meshIndex].counter++;
|
2015-06-19 11:24:37 +02:00
|
|
|
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-07-01 10:14:15 +02:00
|
|
|
};
|
2015-06-15 17:04:19 +02:00
|
|
|
|
2015-06-29 10:43:29 +02:00
|
|
|
geo.MeshStreamer.prototype.isFinished = function(i) {
|
|
|
|
|
|
|
|
return this.meshFaces[i].counter === this.meshFaces[i].array.length;
|
|
|
|
|
2015-07-01 10:14:15 +02:00
|
|
|
};
|