From 968d488b4bd7ec9c4735b4ccbcc75ba4cdb988f4 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 2 Jun 2015 09:42:04 +0200 Subject: [PATCH] Lot of cleaning --- js/prototype/initScene.js | 119 ++++++++++++++++++++++++++++++++++++++ js/prototype/main.js | 37 ++---------- js/prototype/tutorial.js | 38 +----------- 3 files changed, 127 insertions(+), 67 deletions(-) diff --git a/js/prototype/initScene.js b/js/prototype/initScene.js index ac7f2f8..7a4d66a 100644 --- a/js/prototype/initScene.js +++ b/js/prototype/initScene.js @@ -1,6 +1,16 @@ // Define RecommendedCamera if not defined var RecommendedCamera = RecommendedCamera || FixedCamera; +function addLight(scene) { + var directional_light = new THREE.DirectionalLight(0xdddddd); + directional_light.position.set(1, 2.5, 1).normalize(); + directional_light.castShadow = false; + scene.add(directional_light); + + var ambient_light = new THREE.AmbientLight(0x555555); + scene.add(ambient_light); +} + function initPeachCastle(scene, collidableObjects, loader, static_path) { // Create loader if not already done if (loader === undefined) { @@ -79,6 +89,26 @@ function resetPeachElements() { }; } +function initPeach(camera, scene, static_path) { + addLight(scene); + var loader = new THREE.OBJMTLLoader(); + + var collidableObjects = []; + initPeachCastle(scene, collidableObjects, loader, static_path); + + camera.resetElements = resetPeachElements(); + camera.collidableObjects = collidableObjects; + + camera.speed = 0.001; + camera.reset(); + camera.save(); + + scene.add(camera); + + Coin.init(0.001); + coins = []; +} + function initZeldaScene(scene, collidableObjects, loader, static_path) { // Create loader if not already done if (loader === undefined) { @@ -370,6 +400,33 @@ function createBobombCameras(width, height) { } +function initBobomb(camera, scene, static_path, container_size) { + addLight(scene); + var loader = new THREE.OBJMTLLoader(); + + var collidableObjects = []; + initBobombScene(scene, collidableObjects, loader, static_path); + + camera.resetElements = resetBobombElements(); + camera.collidableObjects = collidableObjects; + + camera.speed = 0.005; + camera.reset(); + camera.save(); + + scene.add(camera); + + Coin.init(); + coins = createBobombCoins(); + + var otherCams = createBobombCameras(container_size.width(), container_size.height()); + cameras = new CameraContainer(camera, otherCams); + + otherCams.forEach(function(cam) {cam.addToScene(scene);}); + + setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000); +} + function initWhompScene(scene, collidableObjects, loader, static_path) { loader.load( static_path + './data/whomp/Whomps Fortress.obj', @@ -418,6 +475,33 @@ function resetWhompElements() { }; } +function initWhomp(camera, scene, static_path, container_size) { + addLight(scene); + var loader = new THREE.OBJMTLLoader(); + + var collidableObjects = []; + initWhompScene(scene, collidableObjects, loader, static_path); + + camera.resetElements = resetWhompElements(); + camera.collidableObjects = collidableObjects; + + camera.speed = 0.01; + camera.reset(); + camera.save(); + + scene.add(camera); + + Coin.init(); + coins = createWhompCoins(); + + var otherCams = createWhompCameras(container_size.width(), container_size.height()); + cameras = new CameraContainer(camera, otherCams); + + otherCams.forEach(function(cam) {cam.addToScene(scene);}); + + setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000); +} + function initMountainScene(scene, collidableObjects, loader, static_path) { loader.load( static_path + './data/mountain/coocoolmountain.obj', @@ -456,9 +540,44 @@ function initMountainScene(scene, collidableObjects, loader, static_path) { ); } +function createMountainCoins() { + return []; +} + +function createMountainCameras(width, height) { + return []; +} + function resetMountainElements() { return { position : new THREE.Vector3(-20.558328115300082,23.601312087942762,-10.220633604814038), target : new THREE.Vector3(11.025356711105232,11.969889531789319,11.393733425161644) } } + +function initMountain(camera, scene, static_path, container_size) { + addLight(scene); + var loader = new THREE.OBJMTLLoader(); + + var collidableObjects = []; + initMountainScene(scene, collidableObjects, loader, static_path); + + camera.resetElements = resetMountainElements(); + camera.collidableObjects = collidableObjects; + + camera.speed = 0.005; + camera.reset(); + camera.save(); + + scene.add(camera); + + Coin.init(); + coins = createMountainCoins(); + + var otherCams = createMountainCameras(container_size.width(), container_size.height()); + cameras = new CameraContainer(camera, otherCams); + + otherCams.forEach(function(cam) {cam.addToScene(scene);}); + + setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000); +} diff --git a/js/prototype/main.js b/js/prototype/main.js index fe22abe..ca304d3 100644 --- a/js/prototype/main.js +++ b/js/prototype/main.js @@ -39,6 +39,8 @@ init(); animate(); function init() { + BD.disable(); + // Collidable objects to prevent camera from traversing objects var collidableObjects = new Array(); @@ -73,41 +75,12 @@ function init() { container.appendChild(previewer.domElement); container.appendChild(renderer.domElement); - // init light - var directional_light = new THREE.DirectionalLight(0xdddddd); - directional_light.position.set(1, 2.5, 1).normalize(); - directional_light.castShadow = false; - scene.add(directional_light); - - var ambient_light = new THREE.AmbientLight(0x555555); - scene.add(ambient_light); - // Initialize pointer camera var camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, container); - camera1.speed = 0.005; - camera1.reset(); - camera1.save(); - scene.add(camera1); - // Collisions - camera1.collidableObjects = collidableObjects; - - - // Initialize recommendations - var otherCams = createBobombCameras(container_size.width(), container_size.height()); - cameras = new CameraContainer(camera1, otherCams); - otherCams.forEach(function(cam) { cam.addToScene(scene); }); - - // Initalize loader - var loader = new THREE.OBJMTLLoader(); - - // Load scene - // initPeachCastle(scene, collidableObjects, loader, static_path); - initBobombScene(scene, collidableObjects, loader, static_path); - Coin.init(); - coins = createBobombCoins(); - - setTimeout(function() {coins.forEach(function(coin) { coin.addToScene(scene);})}, 1000); + // initBobomb(camera1, scene, static_path, container_size); + // initWhomp(camera1, scene, static_path, container_size); + initMountain(camera1, scene, static_path, container_size); // Add listeners initListeners(); diff --git a/js/prototype/tutorial.js b/js/prototype/tutorial.js index 15f893a..219e149 100644 --- a/js/prototype/tutorial.js +++ b/js/prototype/tutorial.js @@ -76,47 +76,15 @@ function init() { container.appendChild(previewer.domElement); container.appendChild(renderer.domElement); - // init light - var directional_light = new THREE.DirectionalLight(0xdddddd); - directional_light.position.set(1, 2.5, 1).normalize(); - directional_light.castShadow = false; - scene.add(directional_light); - - var ambient_light = new THREE.AmbientLight(0x555555); - scene.add(ambient_light); - // Initialize pointer camera var camera1 = new TutoCamera(50, container_size.width() / container_size.height(), 0.01, 100000, container); tutorial = camera1.tutorial; - camera1.speed = 0.001; - camera1.resetElements = resetPeachElements(); - camera1.reset(); - camera1.save(); - scene.add(camera1); - // Collisions - camera1.collidableObjects = collidableObjects; + cameras = new CameraContainer(camera1, []); + // Load peach scene + initPeach(camera1, scene, static_path); - // Initialize recommendations - // var otherCams = createBobombCameras(container_size.width(), container_size.height()); - var otherCams = []; // createPeachCameras(container_size.width(), container_size.height()); - cameras = new CameraContainer(camera1, otherCams); - otherCams.forEach(function(cam) {cam.setSize(0.2); cam.addToScene(scene);}); - - // Initalize loader - var loader = new THREE.OBJMTLLoader(); - - // Load scene - initPeachCastle(scene, collidableObjects, loader, static_path); - // initBobombScene(scene, collidableObjects, loader, static_path); - - Coin.init(0.001); - coins = []; - // coins = createBobombCoins(); - // setTimeout(function() {coins.forEach(function(coin) { coin.addToScene(scene);})}, 1000); - - // Add listeners initListeners(); tutorial.nextStep();