From 9c9232d57b4eaf8b4a2e9d349fcae499bd7ef612 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Thu, 18 Jun 2015 15:03:06 +0200 Subject: [PATCH] Clean --- geo/MeshStreamer.js | 84 ++++++++++++++++++++++----------------- js/prototype/initScene.js | 40 +++++++++++++++---- js/stream/main.js | 2 +- 3 files changed, 81 insertions(+), 45 deletions(-) diff --git a/geo/MeshStreamer.js b/geo/MeshStreamer.js index 2dbdc4c..746b63a 100644 --- a/geo/MeshStreamer.js +++ b/geo/MeshStreamer.js @@ -169,24 +169,30 @@ geo.MeshStreamer.prototype.start = function(socket) { geo.MeshStreamer.prototype.nextElements = function(_camera) { // Prepare camera (and scale to model) - var camera = { - position: { - x: _camera[0]*10, - y: _camera[1]*10, - z: _camera[2]*10 - }, - target: { - x: _camera[3]*10, - y: _camera[4]*10, - z: _camera[5]*10 - } - } + var camera = null; + + if (_camera !== null) { + + var camera = { + position: { + x: _camera[0], + y: _camera[1], + z: _camera[2] + }, + target: { + x: _camera[3], + y: _camera[4], + z: _camera[5] + } + } + + // Compute camera direction + var direction = { + x: camera.target.x - camera.position.x, + y: camera.target.y - camera.position.y, + z: camera.target.z - camera.position.z + } - // Compute camera direction - var direction = { - x: camera.target.x - camera.position.x, - y: camera.target.y - camera.position.y, - z: camera.target.z - camera.position.z } var sent = 0; @@ -239,31 +245,35 @@ geo.MeshStreamer.prototype.nextElements = function(_camera) { var vertex2 = this.vertices[currentFace.b]; var vertex3 = this.vertices[currentFace.c]; - var v1 = { - x: vertex1.x - camera.position.x, - y: vertex1.y - camera.position.y, - z: vertex1.z - camera.position.z - }; + if (camera !== null) { - var v2 = { - x: vertex2.x - camera.position.x, - y: vertex2.y - camera.position.y, - z: vertex2.z - camera.position.z - }; + var v1 = { + x: vertex1.x - camera.position.x, + y: vertex1.y - camera.position.y, + z: vertex1.z - camera.position.z + }; - var v3 = { - x: vertex3.x - camera.position.x, - y: vertex3.y - camera.position.y, - z: vertex3.z - camera.position.z - }; + var v2 = { + x: vertex2.x - camera.position.x, + y: vertex2.y - camera.position.y, + z: vertex2.z - camera.position.z + }; - if ( - direction.x * v1.x + direction.y * v1.y + direction.z * v1.z < 0 && - direction.x * v2.x + direction.y * v2.y + direction.z * v2.z < 0 && + var v3 = { + x: vertex3.x - camera.position.x, + y: vertex3.y - camera.position.y, + z: vertex3.z - camera.position.z + }; + + if ( + direction.x * v1.x + direction.y * v1.y + direction.z * v1.z < 0 && + direction.x * v2.x + direction.y * v2.y + direction.z * v2.z < 0 && direction.x * v3.x + direction.y * v3.y + direction.z * v3.z < 0 - ) { + ) { - continue; + continue; + + } } diff --git a/js/prototype/initScene.js b/js/prototype/initScene.js index 94e0227..8cd5354 100644 --- a/js/prototype/initScene.js +++ b/js/prototype/initScene.js @@ -13,7 +13,7 @@ function addLight(scene) { function initPeachCastle(scene, collidableObjects, loader, camera) { - var loader = new ProgressiveLoader( + var loader = new ProgressiveLoaderGeometry( '/static/data/castle/princess peaches castle (outside).obj', scene, camera, @@ -164,10 +164,10 @@ function createPeachCameras(width, height) { function initBobombScene(scene, collidableObjects, loader, camera) { - var loader = new ProgressiveLoader( + var loader = new ProgressiveLoaderGeometry( static_path + 'data/bobomb/bobomb battlefeild.obj', scene, - camera, + null, function(object) { object.raycastable = true; if (object.material.name === 'Material.071_574B138E_c.bmp' || @@ -310,10 +310,10 @@ function initBobomb(camera, scene, static_path, coins) { function initWhompScene(scene, collidableObjects, loader, camera) { - var loader = new ProgressiveLoader( + var loader = new ProgressiveLoaderGeometry( static_path + 'data/whomp/Whomps Fortress.obj', scene, - camera, + null, function(object) { if (object.material.name === 'Shape_088' || object.material.name === 'Shape_089') { @@ -336,6 +336,18 @@ function initWhompScene(scene, collidableObjects, loader, camera) { loader.obj.rotation.x = -Math.PI/2; loader.obj.rotation.z = Math.PI/2; loader.obj.scale.set(0.1,0.1,0.1); + + loader.getCamera = function() { + return [ + loader.camera.position.z * 10, + loader.camera.position.x * 10, + loader.camera.position.y * 10, + loader.camera.target.z * 10, + loader.camera.target.x * 10, + loader.camera.target.y * 10 + ]; + } + collidableObjects.push(loader.obj); loader.obj.raycastable = true; } @@ -461,10 +473,10 @@ function initWhomp(camera, scene, static_path, coins) { function initMountainScene(scene, collidableObjects, loader, camera) { - var loader = new ProgressiveLoader( + var loader = new ProgressiveLoaderGeometry( static_path + 'data/mountain/coocoolmountain.obj', scene, - camera, + null, function(object) { // object.rotation.x = -Math.PI/2; // object.rotation.z = Math.PI/2; @@ -628,11 +640,25 @@ function initSponzaScene(scene, collidableObjects, loader, camera) { l = loader; loader.load(); + + + loader.getCamera = function() { + return [ + loader.camera.position.x * 10, + loader.camera.position.y * 10, + loader.camera.position.z * 10, + loader.camera.target.x * 10, + loader.camera.target.y * 10, + loader.camera.target.z * 10 + ]; + } loader.obj.scale.set(0.1,0.1,0.1); collidableObjects.push(loader.obj); loader.obj.raycastable = true; + + // ProgressiveLoader('/static/data/sponza/sponza.obj', scene, // function(obj) { // obj.scale.set(0.1,0.1,0.1); diff --git a/js/stream/main.js b/js/stream/main.js index 1a0d3f1..cb62b9a 100644 --- a/js/stream/main.js +++ b/js/stream/main.js @@ -45,7 +45,7 @@ function init() { // Load the scene // loader = new THREE.OBJLoader(); - sphereLoader = new ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene); + sphereLoader = new ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene, camera); sphereLoader.load(); sphere = sphereLoader.obj;