Added raycaster to find faces...

This commit is contained in:
Thomas FORGIONE
2015-10-21 15:23:33 +02:00
parent 13f47d467f
commit c760c404a4
6 changed files with 184 additions and 12 deletions

View File

@@ -13,6 +13,7 @@ L3D.ReplayCamera = function() {
this.newTarget = new THREE.Vector3();
this.data = arguments[5];
this.callback = arguments[6];
this.started = true;
this.path = this.data.events;
@@ -94,11 +95,15 @@ L3D.ReplayCamera.prototype.nextEvent = function() {
// Finished
if (this.counter >= this.path.length) {
this.started = false;
console.log('The replay is finished');
// console.log('The replay is finished');
if (typeof this.callback === 'function') {
this.callback();
}
return;
}
this.event = this.path[this.counter];
// console.log(this.event.type);
if (this.event.type == 'camera') {
this.move(this.event);

View File

@@ -163,13 +163,13 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
* Loader for the material file
* @type {THREE.MTLLoader}
*/
this.loader = new THREE.MTLLoader(this.texturesPath);
this.loader = typeof THREE.MTLLoader === 'function' ? new THREE.MTLLoader(this.texturesPath) : null;
/**
* Socket to connect to get the mesh
* @type {socket}
*/
this.socket = io();
this.socket = typeof io === 'function' ? io() : require('socket.io-client').connect('http://localhost:4000');
this.initIOCallbacks();
@@ -210,19 +210,27 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
/**
* Starts the loading of the mesh
*/
ProgressiveLoader.prototype.load = function() {
ProgressiveLoader.prototype.load = function(callback) {
var self = this;
this._callback = callback;
this.loader.load(self.mtlPath, function(materialCreator) {
if (this.loader !== null) {
this.loader.load(self.mtlPath, function(materialCreator) {
self.materialCreator = materialCreator;
self.materialCreator = materialCreator;
materialCreator.preload();
materialCreator.preload();
self.start();
});
} else {
self.start();
});
}
};
/**
@@ -287,7 +295,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
// Create mesh material
var material;
if (elt.materialName === null) {
if (elt.materialName === null || self.materialCreator === undefined) {
// If no material, create a default material
material = new THREE.MeshLambertMaterial({color: 'red'});
@@ -378,7 +386,6 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
});
this.socket.on('disconnect', function() {
console.log('Finished !');
if (typeof self.log === 'function')
self.log(self.numberOfFacesReceived, self.numberOfFaces);
self.finished = true;
@@ -387,6 +394,10 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
L3D.ProgressiveLoader.onFinished();
}
if (typeof self._callback === 'function') {
self._callback();
}
});
};

View File

@@ -41,7 +41,9 @@ L3D.DB.Private.sendData = function(url, data, force) {
* @memberof L3D.DB.Private
* @type {Boolean}
*/
L3D.DB.Private.enabled = !window.DB_DISABLED;
if (typeof module === 'object')
DB_DISABLED = true;
L3D.DB.Private.enabled = !DB_DISABLED;
/**
* Enables the requests