Progressive loader seems finished

This commit is contained in:
Thomas FORGIONE 2015-06-16 15:14:43 +02:00
parent 21321a6ff7
commit 5dfc5e4d4c
6 changed files with 72 additions and 63 deletions

View File

@ -94,13 +94,6 @@ geo.MeshStreamer.prototype.loadFromFile = function(path, callback) {
}
if (currentMesh.faces.length * 3 * 3 > 60000) {
var previousMesh = currentMesh;
currentMesh = new mesh.Mesh();
self.meshes.push(currentMesh);
currentMesh.material = previousMesh.material;
}
} else if (line[0] === 'u') {
// usemtl

View File

@ -241,15 +241,15 @@ PointerCamera.prototype.moveHermite = function(otherCamera, toSave) {
}
PointerCamera.prototype.isColliding = function(direction) {
// this.raycaster.set(this.position, direction.clone().normalize());
// var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);
this.raycaster.set(this.position, direction.clone().normalize());
var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);
/// for (var i in intersects) {
/// if (intersects[i].distance < Tools.norm(direction) + this.speed * 300 &&
/// intersects[i].object.raycastable) {
/// return true;
/// }
/// }
for (var i in intersects) {
if (intersects[i].distance < Tools.norm(direction) + this.speed * 300 &&
intersects[i].object.raycastable) {
return true;
}
}
return false;
}

View File

@ -54,9 +54,9 @@ var _parseList = function(arr) {
var ProgressiveLoader = function(path, scene, callback) {
// Init attributes
this.objPath = path;
this.texturesPath = '/' + path.substring(0, path.lastIndexOf('/')) + '/';
this.mtlPath = '/' + path.replace('.obj', '.mtl');
this.objPath = path.substring(1, path.length);
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/';
this.mtlPath = path.replace('.obj', '.mtl');
this.scene = scene;
this.callback = callback;
this.counter = 0;
@ -102,6 +102,11 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
// console.log("New mesh arrived : " + materialName);
if (self.currentMesh !== undefined && self.currentMesh.visible === false) {
self.currentMesh.geometry.computeBoundingSphere();
if (self.currentMesh.geometry.attributes.normal === undefined) {
self.currentMesh.geometry.computeVertexNormals();
}
self.currentMesh.visible = true;
}
@ -260,6 +265,11 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
this.socket.on('disconnect', function() {
console.log('Finished !');
self.currentMesh.geometry.computeBoundingSphere();
if (self.currentMesh.geometry.attributes.normal === undefined) {
self.currentMesh.geometry.computeVertexNormals();
}
self.currentMesh.visible = true;
self.finished = true;
});
}

View File

@ -14,10 +14,9 @@ function addLight(scene) {
function initPeachCastle(scene, collidableObjects, loader, static_path) {
var loader = new ProgressiveLoader(
'static/data/castle/princess peaches castle (outside).obj',
'/static/data/castle/princess peaches castle (outside).obj',
scene,
function(object) {
collidableObjects.push(object);
object.raycastable = true;
if (object.material.name === 'Material.103_princess_peaches_cast') {
THREEx.Transparency.push(object);
@ -32,6 +31,8 @@ function initPeachCastle(scene, collidableObjects, loader, static_path) {
);
loader.load();
collidableObjects.push(loader.obj);
loader.obj.raycastable = true;
}
function resetPeachElements() {
@ -79,7 +80,6 @@ function initZeldaScene(scene, collidableObjects, loader, static_path) {
static_path + 'data/zelda/Island.obj',
static_path + 'data/zelda/Island.mtl',
function ( object ) {
scene.add(object);
collidableObjects.push(object);
object.scale.set(0.01,0.01,0.01);
object.traverse(function (object) {
@ -161,15 +161,10 @@ function createPeachCameras(width, height) {
function initBobombScene(scene, collidableObjects, loader, static_path) {
ProgressiveLoader(
var loader = new ProgressiveLoader(
static_path + 'data/bobomb/bobomb battlefeild.obj',
scene,
function(object) {
var theta = 0.27;
object.rotation.y = Math.PI - theta;
object.up = new THREE.Vector3(0,0,1);
collidableObjects.push(object);
object.raycastable = true;
if (object.material.name === 'Material.071_574B138E_c.bmp' ||
object.material.name === 'Material.070_41A41EE3_c.bmp') {
@ -178,6 +173,13 @@ function initBobombScene(scene, collidableObjects, loader, static_path) {
}
);
loader.load();
var theta = 0.27;
loader.obj.rotation.y = Math.PI - theta;
loader.obj.up = new THREE.Vector3(0,0,1);
collidableObjects.push(loader.obj);
}
function resetBobombElements() {
@ -304,15 +306,10 @@ function initBobomb(camera, scene, static_path, coins) {
function initWhompScene(scene, collidableObjects, loader, static_path) {
ProgressiveLoader(
var loader = new ProgressiveLoader(
static_path + 'data/whomp/Whomps Fortress.obj',
scene,
function(object) {
object.rotation.x = -Math.PI/2;
object.rotation.z = Math.PI/2;
object.scale.set(0.1,0.1,0.1);
collidableObjects.push(object);
object.raycastable = true;
if (object.material.name === 'Shape_088' ||
object.material.name === 'Shape_089') {
object.raycastable = false;
@ -328,6 +325,14 @@ function initWhompScene(scene, collidableObjects, loader, static_path) {
}
);
loader.load();
loader.obj.rotation.x = -Math.PI/2;
loader.obj.rotation.z = Math.PI/2;
loader.obj.scale.set(0.1,0.1,0.1);
collidableObjects.push(loader.obj);
loader.obj.raycastable = true;
}
function createWhompCameras(width, height) {
@ -451,14 +456,12 @@ function initWhomp(camera, scene, static_path, coins) {
function initMountainScene(scene, collidableObjects, loader, static_path) {
ProgressiveLoader(
var loader = new ProgressiveLoader(
static_path + 'data/mountain/coocoolmountain.obj',
scene,
function(object) {
// object.rotation.x = -Math.PI/2;
// object.rotation.z = Math.PI/2;
collidableObjects.push(object);
scene.add(object);
object.raycastable = true;
if (object.material.name === 'Material.070_13F025D5_c2.png' ||
object.material.name === 'Material.068_5972FC88_c.bmp' ||
@ -477,6 +480,9 @@ function initMountainScene(scene, collidableObjects, loader, static_path) {
}
}
);
loader.load();
collidableObjects.push(loader.obj);
}
function createMountainCoins() {
@ -601,7 +607,7 @@ function initMountain(camera, scene, static_path, coins) {
function initSponzaScene(scene, collidableObjects, loader, static_path) {
var loader = new ProgressiveLoader('static/data/sponza/sponza.obj', scene, function(obj) {
var loader = new ProgressiveLoader('/static/data/sponza/sponza.obj', scene, function(obj) {
if (obj.material.name === 'chain' ||
obj.material.name === 'leaf' ||
obj.material.name === 'Material__57') {

46
js/prototype/main.js vendored
View File

@ -78,8 +78,8 @@ function init() {
// Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container);
// cameras = initMainScene(camera1, scene, static_path, coins);
cameras = initPeach(camera1, scene, static_path, coins);
cameras = initMainScene(camera1, scene, static_path, coins);
// cameras = initPeach(camera1, scene, static_path, coins);
// cameras = initBobomb(camera1, scene, static_path, coins);
// cameras = initWhomp(camera1, scene, static_path, coins);
// cameras = initMountain(camera1, scene, static_path, coins);
@ -116,22 +116,22 @@ function initListeners() {
}
function render() {
// cameraSelecter.update();
cameraSelecter.update();
// // Update recommendations (set raycastable if shown)
// var transform = buttonManager.showArrows ? show : hide;
// cameras.map(function(camera) {
// if (camera instanceof RecommendedCamera) {
// transform(camera);
// Update recommendations (set raycastable if shown)
var transform = buttonManager.showArrows ? show : hide;
cameras.map(function(camera) {
if (camera instanceof RecommendedCamera) {
transform(camera);
// camera.traverse(function(elt) {
// elt.raycastable = buttonManager.showArrows;
// });
// }
// });
camera.traverse(function(elt) {
elt.raycastable = buttonManager.showArrows;
});
}
});
// Update coins
// coins.forEach(function(coin) { coin.update(); });
coins.forEach(function(coin) { coin.update(); });
// Update main camera
var currentTime = Date.now() - previousTime;
@ -139,29 +139,29 @@ function render() {
previousTime = Date.now();
// Update the recommendations
// cameras.update(cameras.mainCamera());
cameras.update(cameras.mainCamera());
// Set current position of camera
cameras.look();
// var left = 0, bottom = 0, width = container_size.width(), height = container_size.height();
// renderer.setScissor(left, bottom, width, height);
// renderer.enableScissorTest(true);
// renderer.setViewport(left, bottom, width, height);
var left = 0, bottom = 0, width = container_size.width(), height = container_size.height();
renderer.setScissor(left, bottom, width, height);
renderer.enableScissorTest(true);
renderer.setViewport(left, bottom, width, height);
renderer.render(scene, cameras.mainCamera());
// Remove borders of preview
// previewer.clear();
previewer.clear();
// Hide arrows in recommendation
// cameras.map(function(camera) { if (camera instanceof RecommendedCamera) hide(camera); });
cameras.map(function(camera) { if (camera instanceof RecommendedCamera) hide(camera); });
// Update transparent elements
// THREEx.Transparency.update(cameras.mainCamera());
THREEx.Transparency.update(cameras.mainCamera());
// Render preview
// previewer.render(cameraSelecter.prev, container_size.width(), container_size.height());
previewer.render(cameraSelecter.prev, container_size.width(), container_size.height());
}
function animate() {

View File

@ -45,7 +45,7 @@ function init() {
// Initialize scene
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer({alpha:true, antialias:true});
renderer = new THREE.WebGLRenderer({alpha:true});
// Collidable objects to prevent camera from traversing objects
var collidableObjects = new Array();
@ -56,7 +56,7 @@ function init() {
container.style.width = container_size.width() + 'px';
renderer.setSize(container_size.width(), container_size.height());
// renderer.setSize(container_size.width(), container_size.height());
renderer.shadowMapEnabled = true;
renderer.shadowMapEnabled = false;
renderer.setClearColor(0x87ceeb);
// Initialize previewer
@ -79,7 +79,7 @@ function init() {
container.appendChild(renderer.domElement);
// Initialize pointer camera
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.1, 100000, renderer, container);
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.1, 1000, renderer, container);
// cameras = initMainScene(camera1, scene, static_path, coins);
// cameras = initPeach(camera1, scene, static_path, coins);