It seems to work now

This commit is contained in:
Thomas FORGIONE 2015-06-18 14:46:09 +02:00
parent b94725ab7c
commit 547162e9bb
4 changed files with 33 additions and 32 deletions

View File

@ -81,19 +81,7 @@ mesh.Mesh.prototype.addNormal = function(normal) {
} }
mesh.Mesh.prototype.isFinished = function() { mesh.Mesh.prototype.isFinished = function() {
// return this.faceIndex === this.faces.length; return this.faceIndex === this.faces.length;
for (var i = 0; i < this.faces.length; i++) {
if (!(this.faces[i].sent)) {
return false;
}
}
return true;
} }
// Vertex // Vertex

View File

@ -85,13 +85,13 @@ geo.MeshStreamer.prototype.loadFromFile = function(path, callback) {
// Create faces (two if Face4) // Create faces (two if Face4)
var faces = currentMesh.addFaces(line); var faces = currentMesh.addFaces(line);
faces[0].index = currentMesh.faces.length - (faces.length === 2 ? 1 : 2); faces[0].index = self.faces.length;
faces[0].meshIndex = self.meshes.length - 1; faces[0].meshIndex = self.meshes.length - 1;
self.faces.push(faces[0]); self.faces.push(faces[0]);
if (faces.length === 2) { if (faces.length === 2) {
faces[1].index = currentMesh.faces.length - 1; faces[1].index = self.faces.length;
faces[1].meshIndex = self.meshes.length - 1; faces[1].meshIndex = self.meshes.length - 1;
self.faces.push(faces[1]); self.faces.push(faces[1]);
@ -189,9 +189,10 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) {
z: camera.target.z - camera.position.z z: camera.target.z - camera.position.z
} }
var sent = 0;; var sent = 0;
var data = []; var data = [];
var mightBeCompletetlyFinished = true; var mightBeCompletetlyFinished = true;
for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) { for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {

View File

@ -65,6 +65,7 @@ var _parseList2 = function(arr) {
} }
var ProgressiveLoaderGeometry = function(path, scene, camera, callback) { var ProgressiveLoaderGeometry = function(path, scene, camera, callback) {
// Init attributes // Init attributes
this.objPath = path.substring(1, path.length); this.objPath = path.substring(1, path.length);
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/'; this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/';
@ -81,6 +82,7 @@ var ProgressiveLoaderGeometry = function(path, scene, camera, callback) {
this.texCoords = []; this.texCoords = [];
this.normals = []; this.normals = [];
this.uvs = []; this.uvs = [];
this.meshes = [];
// Init MTLLoader // Init MTLLoader
this.loader = new THREE.MTLLoader(this.texturesPath); this.loader = new THREE.MTLLoader(this.texturesPath);
@ -141,7 +143,6 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var elt = _parseList2(arr[i]); var elt = _parseList2(arr[i]);
// console.log(arr[i]);
// console.log(elts); // console.log(elts);
if (elt.type === 'vertex') { if (elt.type === 'vertex') {
@ -216,9 +217,9 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
// Create mesh // Create mesh
var mesh = new THREE.Mesh(geometry, material); var mesh = new THREE.Mesh(geometry, material);
self.meshes.push(mesh);
self.currentMesh = mesh; self.currentMesh = mesh;
self.obj.add(mesh);
if (typeof self.callback === 'function') { if (typeof self.callback === 'function') {
self.callback(mesh); self.callback(mesh);
@ -226,18 +227,31 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
} else if (elt.type === 'face') { } else if (elt.type === 'face') {
self.obj.children[elt.mesh].geometry.faces.push(new THREE.Face3(elt.a, elt.b, elt.c, [self.normals[elt.aNormal], self.normals[elt.bNormal], self.normals[elt.cNormal]])); if (!self.meshes[elt.mesh].added) {
if (elt.aTexture !== undefined) { self.meshes[elt.mesh].added = true;
self.obj.add(self.meshes[elt.mesh]);
self.obj.children[elt.mesh].geometry.faceVertexUvs[0].push([self.texCoords[elt.aTexture], self.texCoords[elt.bTexture], self.texCoords[elt.cTexture]]);
} }
self.obj.children[elt.mesh].geometry.verticesNeedUpdate = true; if (elt.aNormal !== undefined) {
self.obj.children[elt.mesh].geometry.uvsNeedUpdate = true; self.meshes[elt.mesh].geometry.faces.push(new THREE.Face3(elt.a, elt.b, elt.c, [self.normals[elt.aNormal], self.normals[elt.bNormal], self.normals[elt.cNormal]]));
self.obj.children[elt.mesh].geometry.normalsNeedUpdate = true; } else {
self.obj.children[elt.mesh].geometry.groupsNeedUpdate = true; self.meshes[elt.mesh].geometry.faces.push(new THREE.Face3(elt.a, elt.b, elt.c));
self.meshes[elt.mesh].geometry.computeFaceNormals();
self.meshes[elt.mesh].geometry.computeVertexNormals();
}
if (elt.aTexture !== undefined) {
self.meshes[elt.mesh].geometry.faceVertexUvs[0].push([self.texCoords[elt.aTexture], self.texCoords[elt.bTexture], self.texCoords[elt.cTexture]]);
}
self.meshes[elt.mesh].geometry.verticesNeedUpdate = true;
self.meshes[elt.mesh].geometry.uvsNeedUpdate = true;
self.meshes[elt.mesh].geometry.normalsNeedUpdate = true;
self.meshes[elt.mesh].geometry.groupsNeedUpdate = true;
} }
@ -249,10 +263,6 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
this.socket.on('disconnect', function() { this.socket.on('disconnect', function() {
console.log('Finished !'); console.log('Finished !');
self.currentMesh.geometry.computeBoundingSphere();
// if (self.currentMesh.geometry.attributes.normal === undefined) {
// self.currentMesh.geometry.computeVertexNormals();
// }
self.finished = true; self.finished = true;
}); });
} }

View File

@ -38,8 +38,10 @@ function initPeachCastle(scene, collidableObjects, loader, camera) {
function resetPeachElements() { function resetPeachElements() {
return { return {
position: new THREE.Vector3(0.24120226734236713,0.2009624547018851,-0.5998422840047036), // position: new THREE.Vector3(0.24120226734236713,0.2009624547018851,-0.5998422840047036),
target: new THREE.Vector3(0.24120226734232672,0.20096245470190008,-40.5998422840047) // target: new THREE.Vector3(0.24120226734232672,0.20096245470190008,-40.5998422840047)
position: new THREE.Vector3(1.4172594473140818,0.7422266244449804,-6.745110400697304),
target: new THREE.Vector3(1.217322777130804,-0.25766921214350846,-46.732111209008615)
}; };
} }