Progressive loader seems finished
This commit is contained in:
parent
21321a6ff7
commit
5dfc5e4d4c
|
@ -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') {
|
} else if (line[0] === 'u') {
|
||||||
|
|
||||||
// usemtl
|
// usemtl
|
||||||
|
|
|
@ -241,15 +241,15 @@ PointerCamera.prototype.moveHermite = function(otherCamera, toSave) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PointerCamera.prototype.isColliding = function(direction) {
|
PointerCamera.prototype.isColliding = function(direction) {
|
||||||
// this.raycaster.set(this.position, direction.clone().normalize());
|
this.raycaster.set(this.position, direction.clone().normalize());
|
||||||
// var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);
|
var intersects = this.raycaster.intersectObjects(this.collidableObjects, true);
|
||||||
|
|
||||||
/// for (var i in intersects) {
|
for (var i in intersects) {
|
||||||
/// if (intersects[i].distance < Tools.norm(direction) + this.speed * 300 &&
|
if (intersects[i].distance < Tools.norm(direction) + this.speed * 300 &&
|
||||||
/// intersects[i].object.raycastable) {
|
intersects[i].object.raycastable) {
|
||||||
/// return true;
|
return true;
|
||||||
/// }
|
}
|
||||||
/// }
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,9 @@ var _parseList = function(arr) {
|
||||||
|
|
||||||
var ProgressiveLoader = function(path, scene, callback) {
|
var ProgressiveLoader = function(path, scene, callback) {
|
||||||
// Init attributes
|
// Init attributes
|
||||||
this.objPath = path;
|
this.objPath = path.substring(1, path.length);
|
||||||
this.texturesPath = '/' + path.substring(0, path.lastIndexOf('/')) + '/';
|
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/';
|
||||||
this.mtlPath = '/' + path.replace('.obj', '.mtl');
|
this.mtlPath = path.replace('.obj', '.mtl');
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.counter = 0;
|
this.counter = 0;
|
||||||
|
@ -102,6 +102,11 @@ ProgressiveLoader.prototype.initIOCallbacks = function() {
|
||||||
// console.log("New mesh arrived : " + materialName);
|
// console.log("New mesh arrived : " + materialName);
|
||||||
if (self.currentMesh !== undefined && self.currentMesh.visible === false) {
|
if (self.currentMesh !== undefined && self.currentMesh.visible === false) {
|
||||||
self.currentMesh.geometry.computeBoundingSphere();
|
self.currentMesh.geometry.computeBoundingSphere();
|
||||||
|
|
||||||
|
if (self.currentMesh.geometry.attributes.normal === undefined) {
|
||||||
|
self.currentMesh.geometry.computeVertexNormals();
|
||||||
|
}
|
||||||
|
|
||||||
self.currentMesh.visible = true;
|
self.currentMesh.visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +265,11 @@ ProgressiveLoader.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.currentMesh.visible = true;
|
||||||
self.finished = true;
|
self.finished = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,9 @@ function addLight(scene) {
|
||||||
function initPeachCastle(scene, collidableObjects, loader, static_path) {
|
function initPeachCastle(scene, collidableObjects, loader, static_path) {
|
||||||
|
|
||||||
var loader = new ProgressiveLoader(
|
var loader = new ProgressiveLoader(
|
||||||
'static/data/castle/princess peaches castle (outside).obj',
|
'/static/data/castle/princess peaches castle (outside).obj',
|
||||||
scene,
|
scene,
|
||||||
function(object) {
|
function(object) {
|
||||||
collidableObjects.push(object);
|
|
||||||
object.raycastable = true;
|
object.raycastable = true;
|
||||||
if (object.material.name === 'Material.103_princess_peaches_cast') {
|
if (object.material.name === 'Material.103_princess_peaches_cast') {
|
||||||
THREEx.Transparency.push(object);
|
THREEx.Transparency.push(object);
|
||||||
|
@ -32,6 +31,8 @@ function initPeachCastle(scene, collidableObjects, loader, static_path) {
|
||||||
);
|
);
|
||||||
loader.load();
|
loader.load();
|
||||||
|
|
||||||
|
collidableObjects.push(loader.obj);
|
||||||
|
loader.obj.raycastable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetPeachElements() {
|
function resetPeachElements() {
|
||||||
|
@ -79,7 +80,6 @@ function initZeldaScene(scene, collidableObjects, loader, static_path) {
|
||||||
static_path + 'data/zelda/Island.obj',
|
static_path + 'data/zelda/Island.obj',
|
||||||
static_path + 'data/zelda/Island.mtl',
|
static_path + 'data/zelda/Island.mtl',
|
||||||
function ( object ) {
|
function ( object ) {
|
||||||
scene.add(object);
|
|
||||||
collidableObjects.push(object);
|
collidableObjects.push(object);
|
||||||
object.scale.set(0.01,0.01,0.01);
|
object.scale.set(0.01,0.01,0.01);
|
||||||
object.traverse(function (object) {
|
object.traverse(function (object) {
|
||||||
|
@ -161,15 +161,10 @@ function createPeachCameras(width, height) {
|
||||||
|
|
||||||
function initBobombScene(scene, collidableObjects, loader, static_path) {
|
function initBobombScene(scene, collidableObjects, loader, static_path) {
|
||||||
|
|
||||||
ProgressiveLoader(
|
var loader = new ProgressiveLoader(
|
||||||
static_path + 'data/bobomb/bobomb battlefeild.obj',
|
static_path + 'data/bobomb/bobomb battlefeild.obj',
|
||||||
scene,
|
scene,
|
||||||
function(object) {
|
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;
|
object.raycastable = true;
|
||||||
if (object.material.name === 'Material.071_574B138E_c.bmp' ||
|
if (object.material.name === 'Material.071_574B138E_c.bmp' ||
|
||||||
object.material.name === 'Material.070_41A41EE3_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() {
|
function resetBobombElements() {
|
||||||
|
@ -304,15 +306,10 @@ function initBobomb(camera, scene, static_path, coins) {
|
||||||
|
|
||||||
function initWhompScene(scene, collidableObjects, loader, static_path) {
|
function initWhompScene(scene, collidableObjects, loader, static_path) {
|
||||||
|
|
||||||
ProgressiveLoader(
|
var loader = new ProgressiveLoader(
|
||||||
static_path + 'data/whomp/Whomps Fortress.obj',
|
static_path + 'data/whomp/Whomps Fortress.obj',
|
||||||
scene,
|
scene,
|
||||||
function(object) {
|
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' ||
|
if (object.material.name === 'Shape_088' ||
|
||||||
object.material.name === 'Shape_089') {
|
object.material.name === 'Shape_089') {
|
||||||
object.raycastable = false;
|
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) {
|
function createWhompCameras(width, height) {
|
||||||
|
@ -451,14 +456,12 @@ function initWhomp(camera, scene, static_path, coins) {
|
||||||
|
|
||||||
function initMountainScene(scene, collidableObjects, loader, static_path) {
|
function initMountainScene(scene, collidableObjects, loader, static_path) {
|
||||||
|
|
||||||
ProgressiveLoader(
|
var loader = new ProgressiveLoader(
|
||||||
static_path + 'data/mountain/coocoolmountain.obj',
|
static_path + 'data/mountain/coocoolmountain.obj',
|
||||||
scene,
|
scene,
|
||||||
function(object) {
|
function(object) {
|
||||||
// object.rotation.x = -Math.PI/2;
|
// object.rotation.x = -Math.PI/2;
|
||||||
// object.rotation.z = Math.PI/2;
|
// object.rotation.z = Math.PI/2;
|
||||||
collidableObjects.push(object);
|
|
||||||
scene.add(object);
|
|
||||||
object.raycastable = true;
|
object.raycastable = true;
|
||||||
if (object.material.name === 'Material.070_13F025D5_c2.png' ||
|
if (object.material.name === 'Material.070_13F025D5_c2.png' ||
|
||||||
object.material.name === 'Material.068_5972FC88_c.bmp' ||
|
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() {
|
function createMountainCoins() {
|
||||||
|
@ -601,7 +607,7 @@ function initMountain(camera, scene, static_path, coins) {
|
||||||
|
|
||||||
function initSponzaScene(scene, collidableObjects, loader, static_path) {
|
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' ||
|
if (obj.material.name === 'chain' ||
|
||||||
obj.material.name === 'leaf' ||
|
obj.material.name === 'leaf' ||
|
||||||
obj.material.name === 'Material__57') {
|
obj.material.name === 'Material__57') {
|
||||||
|
|
|
@ -78,8 +78,8 @@ function init() {
|
||||||
// Initialize pointer camera
|
// Initialize pointer camera
|
||||||
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container);
|
var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container);
|
||||||
|
|
||||||
// cameras = initMainScene(camera1, scene, static_path, coins);
|
cameras = initMainScene(camera1, scene, static_path, coins);
|
||||||
cameras = initPeach(camera1, scene, static_path, coins);
|
// cameras = initPeach(camera1, scene, static_path, coins);
|
||||||
// cameras = initBobomb(camera1, scene, static_path, coins);
|
// cameras = initBobomb(camera1, scene, static_path, coins);
|
||||||
// cameras = initWhomp(camera1, scene, static_path, coins);
|
// cameras = initWhomp(camera1, scene, static_path, coins);
|
||||||
// cameras = initMountain(camera1, scene, static_path, coins);
|
// cameras = initMountain(camera1, scene, static_path, coins);
|
||||||
|
@ -116,22 +116,22 @@ function initListeners() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
// cameraSelecter.update();
|
cameraSelecter.update();
|
||||||
|
|
||||||
// // Update recommendations (set raycastable if shown)
|
// Update recommendations (set raycastable if shown)
|
||||||
// var transform = buttonManager.showArrows ? show : hide;
|
var transform = buttonManager.showArrows ? show : hide;
|
||||||
// cameras.map(function(camera) {
|
cameras.map(function(camera) {
|
||||||
// if (camera instanceof RecommendedCamera) {
|
if (camera instanceof RecommendedCamera) {
|
||||||
// transform(camera);
|
transform(camera);
|
||||||
|
|
||||||
// camera.traverse(function(elt) {
|
camera.traverse(function(elt) {
|
||||||
// elt.raycastable = buttonManager.showArrows;
|
elt.raycastable = buttonManager.showArrows;
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
// Update coins
|
// Update coins
|
||||||
// coins.forEach(function(coin) { coin.update(); });
|
coins.forEach(function(coin) { coin.update(); });
|
||||||
|
|
||||||
// Update main camera
|
// Update main camera
|
||||||
var currentTime = Date.now() - previousTime;
|
var currentTime = Date.now() - previousTime;
|
||||||
|
@ -139,29 +139,29 @@ function render() {
|
||||||
previousTime = Date.now();
|
previousTime = Date.now();
|
||||||
|
|
||||||
// Update the recommendations
|
// Update the recommendations
|
||||||
// cameras.update(cameras.mainCamera());
|
cameras.update(cameras.mainCamera());
|
||||||
|
|
||||||
|
|
||||||
// Set current position of camera
|
// Set current position of camera
|
||||||
cameras.look();
|
cameras.look();
|
||||||
|
|
||||||
// var left = 0, bottom = 0, width = container_size.width(), height = container_size.height();
|
var left = 0, bottom = 0, width = container_size.width(), height = container_size.height();
|
||||||
// renderer.setScissor(left, bottom, width, height);
|
renderer.setScissor(left, bottom, width, height);
|
||||||
// renderer.enableScissorTest(true);
|
renderer.enableScissorTest(true);
|
||||||
// renderer.setViewport(left, bottom, width, height);
|
renderer.setViewport(left, bottom, width, height);
|
||||||
renderer.render(scene, cameras.mainCamera());
|
renderer.render(scene, cameras.mainCamera());
|
||||||
|
|
||||||
// Remove borders of preview
|
// Remove borders of preview
|
||||||
// previewer.clear();
|
previewer.clear();
|
||||||
|
|
||||||
// Hide arrows in recommendation
|
// 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
|
// Update transparent elements
|
||||||
// THREEx.Transparency.update(cameras.mainCamera());
|
THREEx.Transparency.update(cameras.mainCamera());
|
||||||
|
|
||||||
// Render preview
|
// Render preview
|
||||||
// previewer.render(cameraSelecter.prev, container_size.width(), container_size.height());
|
previewer.render(cameraSelecter.prev, container_size.width(), container_size.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
function animate() {
|
function animate() {
|
||||||
|
|
|
@ -45,7 +45,7 @@ function init() {
|
||||||
|
|
||||||
// Initialize scene
|
// Initialize scene
|
||||||
scene = new THREE.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
|
// Collidable objects to prevent camera from traversing objects
|
||||||
var collidableObjects = new Array();
|
var collidableObjects = new Array();
|
||||||
|
@ -56,7 +56,7 @@ function init() {
|
||||||
container.style.width = container_size.width() + 'px';
|
container.style.width = container_size.width() + 'px';
|
||||||
renderer.setSize(container_size.width(), container_size.height());
|
renderer.setSize(container_size.width(), container_size.height());
|
||||||
// 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);
|
renderer.setClearColor(0x87ceeb);
|
||||||
|
|
||||||
// Initialize previewer
|
// Initialize previewer
|
||||||
|
@ -79,7 +79,7 @@ function init() {
|
||||||
container.appendChild(renderer.domElement);
|
container.appendChild(renderer.domElement);
|
||||||
|
|
||||||
// Initialize pointer camera
|
// 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 = initMainScene(camera1, scene, static_path, coins);
|
||||||
// cameras = initPeach(camera1, scene, static_path, coins);
|
// cameras = initPeach(camera1, scene, static_path, coins);
|
||||||
|
|
Loading…
Reference in New Issue