From d05f8e33e0967bc41e2fdf3def9aaf6530365d87 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Thu, 4 Jun 2015 14:43:39 +0200 Subject: [PATCH] Sponza model --- js/prototype/initScene.js | 85 +++++++++++++++++++++++++++++++++++++++ js/prototype/main.js | 5 ++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/js/prototype/initScene.js b/js/prototype/initScene.js index 588f3b8..a02c8e6 100644 --- a/js/prototype/initScene.js +++ b/js/prototype/initScene.js @@ -616,3 +616,88 @@ function initMountain(camera, scene, static_path, coins) { setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000); return cameras; } + +function initSponzaScene(scene, collidableObjects, loader, static_path) { + var onProgress = function ( xhr ) { + if ( xhr.lengthComputable ) { + var percentComplete = xhr.loaded / xhr.total * 100; + console.log( Math.round(percentComplete, 2) + '% downloaded' ); + console.log(xhr); + } + }; + + loader.load( + static_path + './data/sponza/sponza.json', + function (geometry, materials) { + console.log("OK"); + geometry.mergeVertices(); + var material = new THREE.MeshFaceMaterial(materials); + var object = new THREE.Mesh(geometry, material); + object.scale.set(0.01,0.01,0.01); + object.raycastable = true; + collidableObjects.push(object); + console.log(object); + scene.add(object); + // object.rotation.x = -Math.PI/2; + // object.rotation.z = Math.PI/2; + // collidableObjects.push(object); + // scene.add(object); + object.traverse(function (obj) { + // if (obj instanceof THREE.Mesh) { + // obj.geometry.mergeVertices(); + // obj.geometry.computeVertexNormals(); + // obj.material.side = THREE.DoubleSide; + // obj.raycastable = true; + // } + }); + } + , onProgress, function(xhr) { console.log("error");}); +} + +function createSponzaCoins() { + return []; +} + +function createSponzaCameras() { + return []; +} + +function resetSponzaElements() { + return resetMountainElements(); +} + +function initSponza(camera, scene, static_path, coins) { + + addLight(scene); + var loader = new THREE.JSONLoader(); + + var collidableObjects = []; + initSponzaScene(scene, collidableObjects, loader, static_path); + + camera.resetElements = resetSponzaElements(); + camera.collidableObjects = collidableObjects; + + camera.speed = 0.005; + camera.reset(); + camera.save(); + + scene.add(camera); + + Coin.init(); + var tmp = createSponzaCoins(); + + for (var i in tmp) { + coins.push(tmp[i]); + } + + var otherCams = createSponzaCameras(container_size.width(), container_size.height()); + var cameras = new CameraContainer(camera, otherCams); + + otherCams.forEach(function(cam) {cam.addToScene(scene);}); + + setTimeout(function() { coins.forEach(function(coin) { coin.addToScene(scene); })}, 1000); + + + return cameras; + +} diff --git a/js/prototype/main.js b/js/prototype/main.js index 3f29c5f..223f968 100644 --- a/js/prototype/main.js +++ b/js/prototype/main.js @@ -76,11 +76,12 @@ function init() { container.appendChild(renderer.domElement); // 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.1, 100000, renderer, container); - cameras = initBobomb(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); + cameras = initSponza(camera1, scene, static_path, coins); // Add listeners initListeners();