diff --git a/controllers/prototype/index.js b/controllers/prototype/index.js index dd4d4ab..cd13fd2 100644 --- a/controllers/prototype/index.js +++ b/controllers/prototype/index.js @@ -54,13 +54,13 @@ var generateSceneNumber = function(req, res) { var sceneToFunction = function(scene) { switch (scene) { case 2: - return 'initBobomb'; + return 'L3D.initBobomb'; case 3: - return 'initMountain'; + return 'L3D.initMountain'; case 4: - return 'initWhomp'; + return 'L3D.initWhomp'; default: - return 'initPeach'; + return 'L3D.initPeach'; } }; diff --git a/controllers/prototype/views/prototype_arrows.jade b/controllers/prototype/views/prototype_arrows.jade index 9119810..cb7694d 100644 --- a/controllers/prototype/views/prototype_arrows.jade +++ b/controllers/prototype/views/prototype_arrows.jade @@ -4,7 +4,7 @@ block title title #{title} - Prototype - Arrows block configjs - script RecommendedCamera = FixedCamera; + script Recommendation = L3D.ArrowRecommendation; //-block preciseDescription p diff --git a/controllers/prototype/views/prototype_replays.jade b/controllers/prototype/views/prototype_replays.jade index 8d6d90f..748b62b 100644 --- a/controllers/prototype/views/prototype_replays.jade +++ b/controllers/prototype/views/prototype_replays.jade @@ -4,7 +4,7 @@ block title title #{title} - Prototype block extrajs - script RecommendedCamera = FixedCamera; + script Recommendation = L3D.ArrowRecommendation; script var params = params || {}; params.get = params.get || {}; params.get.id = #{id}; script initMainScene = #{initjs} script(src="/static/js/replay.min.js") diff --git a/controllers/prototype/views/sponza.jade b/controllers/prototype/views/sponza.jade index 84b63c1..bb208fa 100644 --- a/controllers/prototype/views/sponza.jade +++ b/controllers/prototype/views/sponza.jade @@ -4,7 +4,7 @@ block title title #{title} - Prototype - Arrows block mainjs - script initMainScene = initSponza + script initMainScene = L3D.initSponza script(src="/static/js/prototypeinteractive.min.js") block configjs diff --git a/controllers/prototype/views/tutorial.jade b/controllers/prototype/views/tutorial.jade index 5d3a783..f6400f5 100644 --- a/controllers/prototype/views/tutorial.jade +++ b/controllers/prototype/views/tutorial.jade @@ -7,7 +7,7 @@ block title title #{title} - Prototype - Tutorial block configjs - script RecommendedCamera = FixedCamera; + script Recommendation = L3D.ArrowRecommendation; script(src="/static/js/tutorial.min.js") block fullscreen diff --git a/js/Makefile b/js/Makefile index f855c86..8361569 100644 --- a/js/Makefile +++ b/js/Makefile @@ -10,9 +10,9 @@ all: L3D L3DP Socket Three Stats Bouncing Multisphere StreamingSimulator Prototy L3D: $(CLOSURE) $(OPT) \ + --js l3d/src/l3d.js \ --js l3d/src/math/Tools.js \ --js l3d/src/math/Hermite.js \ - --js l3d/src/utils/List.js \ --js l3d/src/utils/CameraSelecter.js \ --js l3d/src/utils/Logger.js \ --js l3d/src/utils/Objects.js \ diff --git a/js/l3d/apps/bouncing-cube/BouncingCube.js b/js/l3d/apps/bouncing-cube/BouncingCube.js index ac51096..42d973e 100644 --- a/js/l3d/apps/bouncing-cube/BouncingCube.js +++ b/js/l3d/apps/bouncing-cube/BouncingCube.js @@ -1,12 +1,12 @@ var BouncingCube = function(size, style) { - Cube.call(this, size, style); + L3D.Cube.call(this, size, style); this.fixed_center = new THREE.Vector3(); this.center = new THREE.Vector3(); this.speed = new THREE.Vector3(0,0,300); }; -BouncingCube.prototype = Object.create(Cube.prototype); +BouncingCube.prototype = Object.create(L3D.Cube.prototype); BouncingCube.prototype.constructor = BouncingCube; BouncingCube.prototype.update = function() { diff --git a/js/l3d/apps/bouncing-cube/main.js b/js/l3d/apps/bouncing-cube/main.js index 0dcac7d..58465db 100644 --- a/js/l3d/apps/bouncing-cube/main.js +++ b/js/l3d/apps/bouncing-cube/main.js @@ -33,7 +33,7 @@ function init() { scene.add(ambient_light); // on initialise la camera que l’on place ensuite sur la scène - camera = new Camera(50, container_size.width / container_size.height, 1, 10000); + camera = new L3D.Camera(50, container_size.width / container_size.height, 1, 10000); scene.add(camera); window.addEventListener('resize', onWindowResize, false); @@ -42,7 +42,7 @@ function init() { // on créé un cube au quel on définie un matériau puis on l’ajoute à la scène cube = new BouncingCube(200, {color: "red"}); - plane = new Plane(1000,1000); + plane = new L3D.Plane(1000,1000); plane.translate(0,0,-100); cube.addToScene(scene); diff --git a/js/l3d/apps/multisphere/main.js b/js/l3d/apps/multisphere/main.js index b07b113..fb381d9 100644 --- a/js/l3d/apps/multisphere/main.js +++ b/js/l3d/apps/multisphere/main.js @@ -55,7 +55,7 @@ function init() { scene.add(ambient_light); // on initialise la camera que l’on place ensuite sur la scène - camera = new Camera(50, container_size.width / container_size.height, 1, 10000); + camera = new L3D.Camera(50, container_size.width / container_size.height, 1, 10000); scene.add(camera); window.addEventListener('resize', onWindowResize, false); @@ -71,8 +71,7 @@ function init() { } - - plane = new Plane(1000,1000); + plane = new L3D.Plane(1000,1000); plane.translate(0,0,-100); plane.addToScene(scene); } diff --git a/js/l3d/apps/prototype/interactive/main.js b/js/l3d/apps/prototype/interactive/main.js index 055866b..e031d14 100644 --- a/js/l3d/apps/prototype/interactive/main.js +++ b/js/l3d/apps/prototype/interactive/main.js @@ -44,7 +44,7 @@ var previousTime; window.onbeforeunload = function() { - if (initMainScene !== initPeach && initMainScene !== initSponza && Coin.total !== 9) { + if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza && Coin.total !== 9) { return 'Warning : you are going to leave the page and abort the current test !'; @@ -54,7 +54,7 @@ window.onbeforeunload = function() { init(); -if (initMainScene !== initPeach && initMainScene !== initSponza) +if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza) logfps(); animate(); @@ -63,7 +63,7 @@ function logfps() { // Log fps if (stats !== undefined) { - var event = new BD.Event.Fps(); + var event = new L3D.BD.Event.Fps(); event.fps = stats.getFps(); event.send(); @@ -90,10 +90,10 @@ function init() { renderer.setClearColor(0x87ceeb); // Initialize pointer camera - camera1 = new PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container); + camera1 = new L3D.PointerCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, container); // Initialize previewer - previewer = new Previewer(renderer, scene); + previewer = new L3D.Previewer(renderer, scene); previewer.domElement.style.position ="absolute"; previewer.domElement.style.cssFloat = 'top-left'; previewer.domElement.width = container_size.width(); @@ -106,12 +106,12 @@ function init() { stats.domElement.style.cssFloat = "top-left"; // Initialize pointer for pointer lock - var pointer = new MousePointer(camera1); + var pointer = new L3D.MousePointer(camera1); pointer.domElement.width = container_size.width(); pointer.domElement.height = container_size.height(); // - var startCanvas = new StartCanvas(camera1); + var startCanvas = new L3D.StartCanvas(camera1); startCanvas.domElement.width = container_size.width(); startCanvas.domElement.height = container_size.height(); @@ -126,11 +126,11 @@ function init() { startCanvas.render(); cameras = initMainScene(camera1, scene, coins); - // cameras = initPeach(camera1, scene, coins); - // cameras = initBobomb(camera1, scene, coins); - // cameras = initWhomp(camera1, scene, , coins); - // cameras = initMountain(camera1, scene, coins); - // cameras = initSponza(camera1, scene, coins); + // cameras = L3D.initPeach(camera1, scene, coins); + // cameras = L3D.initBobomb(camera1, scene, coins); + // cameras = L3D.initWhomp(camera1, scene, , coins); + // cameras = L3D.initMountain(camera1, scene, coins); + // cameras = L3D.initSponza(camera1, scene, coins); // Add listeners initListeners(); @@ -168,7 +168,7 @@ function initListeners() { buttonManager = new ButtonManager(cameras, previewer); // Camera selecter for hover and clicking recommendations - cameraSelecter = new CameraSelecter(renderer, scene, cameras, coins, buttonManager); + cameraSelecter = new L3D.CameraSelecter(renderer, scene, cameras, coins, buttonManager); } function render() { @@ -177,7 +177,7 @@ function render() { // Update recommendations (set raycastable if shown) var transform = buttonManager.showArrows ? show : hide; cameras.map(function(camera) { - if (camera instanceof RecommendedCamera) { + if (camera instanceof Recommendation) { transform(camera); camera.traverse(function(elt) { @@ -211,7 +211,7 @@ function render() { previewer.clear(); // Hide arrows in recommendation - cameras.map(function(camera) { if (camera instanceof RecommendedCamera) hide(camera); }); + cameras.map(function(camera) { if (camera instanceof Recommendation) hide(camera); }); // Update transparent elements THREEx.Transparency.update(cameras.mainCamera()); diff --git a/js/l3d/apps/prototype/replay/main.js b/js/l3d/apps/prototype/replay/main.js index 9fdb1fc..146c594 100644 --- a/js/l3d/apps/prototype/replay/main.js +++ b/js/l3d/apps/prototype/replay/main.js @@ -71,7 +71,7 @@ function init() { container.appendChild(renderer.domElement); // Initialize pointer camera - var camera1 = new ReplayCamera(50, container_size.width() / container_size.height(), 0.01, 100000, coins); + var camera1 = new L3D.ReplayCamera(50, container_size.width() / container_size.height(), 0.01, 100000, coins); cameras = initMainScene(camera1, scene, coins); camera1.cameras = cameras; diff --git a/js/l3d/apps/prototype/tutorial/TutoCamera.js b/js/l3d/apps/prototype/tutorial/TutoCamera.js index 286dd9d..36f221a 100644 --- a/js/l3d/apps/prototype/tutorial/TutoCamera.js +++ b/js/l3d/apps/prototype/tutorial/TutoCamera.js @@ -41,7 +41,7 @@ var TutoCamera = function() { this.raycaster = new THREE.Raycaster(); // Create history object - this.history = new History(); + this.history = new L3D.History(); // Set events from the document var self = this; @@ -75,8 +75,6 @@ var TutoCamera = function() { this.collisions = true; - this.resetElements = resetBobombElements(); - // Create tutorial this.tutorial = new TutorialSteps(this, scene, coins, this.onWindowResize, container_size); @@ -169,14 +167,14 @@ TutoCamera.prototype.update = function(time) { }; TutoCamera.prototype.linearMotion = function(time) { - var position_direction = Tools.diff(this.new_position, this.position); - var target_direction = Tools.diff(this.new_target, this.target); + var position_direction = L3D.Tools.diff(this.new_position, this.position); + var target_direction = L3D.Tools.diff(this.new_target, this.target); - this.position.add(Tools.mul(position_direction, 0.05 * time / 20)); - this.target.add(Tools.mul(target_direction, 0.05 * time / 20)); + this.position.add(L3D.Tools.mul(position_direction, 0.05 * time / 20)); + this.target.add(L3D.Tools.mul(target_direction, 0.05 * time / 20)); - if (Tools.norm2(Tools.diff(this.position, this.new_position)) < 0.01 && - Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.01) { + if (L3D.Tools.norm2(L3D.Tools.diff(this.position, this.new_position)) < 0.01 && + L3D.Tools.norm2(L3D.Tools.diff(this.target, this.new_target)) < 0.01) { this.moving = false; this.anglesFromVectors(); } @@ -188,7 +186,7 @@ TutoCamera.prototype.hermiteMotion = function(time) { this.position.y = e.y; this.position.z = e.z; - this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t)); + this.target = L3D.Tools.sum(this.position, this.hermiteAngles.eval(this.t)); this.t += 0.01 * time / 20; @@ -238,18 +236,18 @@ TutoCamera.prototype.normalMotion = function(time) { var direction = new THREE.Vector3(); if (this.motion.boost) speed *= 10; - if (this.motion.moveForward) {direction.add(Tools.mul(forward, speed)); this.changed = true;} - if (this.motion.moveBackward) {direction.sub(Tools.mul(forward, speed)); this.changed = true;} - if (this.motion.moveLeft) {direction.add(Tools.mul(left, speed)); this.changed = true;} - if (this.motion.moveRight) {direction.sub(Tools.mul(left, speed)); this.changed = true;} + if (this.motion.moveForward) {direction.add(L3D.Tools.mul(forward, speed)); this.changed = true;} + if (this.motion.moveBackward) {direction.sub(L3D.Tools.mul(forward, speed)); this.changed = true;} + if (this.motion.moveLeft) {direction.add(L3D.Tools.mul(left, speed)); this.changed = true;} + if (this.motion.moveRight) {direction.sub(L3D.Tools.mul(left, speed)); this.changed = true;} var collide = this.isColliding(direction); if (this.collisions && collide) { var face = collide.face; var vertices = collide.object.geometry.vertices; - var normal = Tools.cross(Tools.diff(vertices[face.b], vertices[face.a]), Tools.diff(vertices[face.c], vertices[face.a])).normalize(); + var normal = L3D.Tools.cross(L3D.Tools.diff(vertices[face.b], vertices[face.a]), L3D.Tools.diff(vertices[face.c], vertices[face.a])).normalize(); - if (Tools.dot(normal, direction) > 0) { + if (L3D.Tools.dot(normal, direction) > 0) { normal.multiplyScalar(-1); } @@ -272,7 +270,7 @@ TutoCamera.prototype.reset = function() { this.resetPosition(); this.moving = false; this.movingHermite = false; - (new BD.Event.ResetClicked()).send(); + (new L3D.BD.Event.ResetClicked()).send(); this.previousTheta = this.theta; this.previousPhi = this.phi; @@ -296,7 +294,7 @@ TutoCamera.prototype.vectorsFromAngles = function() { }; TutoCamera.prototype.anglesFromVectors = function() { - var forward = Tools.diff(this.target, this.position); + var forward = L3D.Tools.diff(this.target, this.position); forward.normalize(); this.phi = Math.asin(forward.y); @@ -315,8 +313,8 @@ TutoCamera.prototype.move = function(otherCamera, toSave) { this.new_position = otherCamera.position.clone(); var t = [0,1]; var f = [this.position.clone(), this.new_position]; - var fp = [Tools.diff(this.target, this.position), Tools.diff(this.new_target, this.new_position)]; - this.hermite = new Hermite.Polynom(t,f,fp); + var fp = [L3D.Tools.diff(this.target, this.position), L3D.Tools.diff(this.new_target, this.new_position)]; + this.hermite = new L3D.Hermite.Polynom(t,f,fp); this.t = 0; if (toSave) { @@ -339,15 +337,15 @@ TutoCamera.prototype.moveHermite = function(otherCamera, toSave) { this.movingHermite = true; this.t = 0; - this.hermitePosition = new Hermite.special.Polynom( + this.hermitePosition = new L3D.Hermite.special.Polynom( this.position.clone(), otherCamera.position.clone(), - Tools.mul(Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) + L3D.Tools.mul(L3D.Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) ); - this.hermiteAngles = new Hermite.special.Polynom( - Tools.diff(this.target, this.position), - Tools.diff(otherCamera.target, otherCamera.position), + this.hermiteAngles = new L3D.Hermite.special.Polynom( + L3D.Tools.diff(this.target, this.position), + L3D.Tools.diff(otherCamera.target, otherCamera.position), new THREE.Vector3() ); @@ -365,7 +363,7 @@ TutoCamera.prototype.isColliding = function(direction) { var intersects = this.raycaster.intersectObjects(this.collidableObjects, true); for (var i in intersects) { - if (intersects[i].distance < Tools.norm(direction) + this.speed * 300 && + if (intersects[i].distance < L3D.Tools.norm(direction) + this.speed * 300 && intersects[i].object.raycastable) { return intersects[i]; } @@ -430,7 +428,7 @@ TutoCamera.prototype.onKeyEvent = function(event, toSet) { if (motionJsonCopy != JSON.stringify(this.motion)) { // Log any change - var e = new BD.Event.KeyboardEvent(); + var e = new L3D.BD.Event.KeyboardEvent(); e.camera = this; e.send(); } @@ -498,7 +496,7 @@ TutoCamera.prototype.onMouseUp = function(event) { // Send log to DB if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) { - var e = new BD.Event.KeyboardEvent(); + var e = new L3D.BD.Event.KeyboardEvent(); e.camera = this; e.send(); } @@ -521,7 +519,7 @@ TutoCamera.prototype.save = function() { TutoCamera.prototype.undo = function() { var move = this.history.undo(); if (move !== undefined) { - var event = new BD.Event.PreviousNextClicked(); + var event = new L3D.BD.Event.PreviousNextClicked(); event.previous = true; event.camera = move; event.send(); @@ -533,7 +531,7 @@ TutoCamera.prototype.undo = function() { TutoCamera.prototype.redo = function() { var move = this.history.redo(); if (move !== undefined) { - var event = new BD.Event.PreviousNextClicked(); + var event = new L3D.BD.Event.PreviousNextClicked(); event.previous = false; event.camera = move; event.send(); diff --git a/js/l3d/apps/prototype/tutorial/TutorialSteps.js b/js/l3d/apps/prototype/tutorial/TutorialSteps.js index ef8a7a7..ff7e96c 100644 --- a/js/l3d/apps/prototype/tutorial/TutorialSteps.js +++ b/js/l3d/apps/prototype/tutorial/TutorialSteps.js @@ -148,7 +148,7 @@ TutorialSteps.prototype.nextStep = function() { }); break; case 14: - var cam = createPeachCameras(this.container_size.width(), this.container_size.height())[2]; + var cam = L3D.createPeachCameras(this.container_size.width(), this.container_size.height())[2]; this.cameras.push(cam); cam.addToScene(this.scene); this.camera.move({ @@ -157,7 +157,7 @@ TutorialSteps.prototype.nextStep = function() { }); break; case 16: - var cams = createPeachCameras(this.container_size.width(), this.container_size.height()); + var cams = L3D.createPeachCameras(this.container_size.width(), this.container_size.height()); for (var i = 0; i < cams.length; i == 1 ? i+=2 : i++) { this.cameras.push(cams[i]); cams[i].addToScene(this.scene); diff --git a/js/l3d/apps/prototype/tutorial/main.js b/js/l3d/apps/prototype/tutorial/main.js index 20a2530..8663e59 100644 --- a/js/l3d/apps/prototype/tutorial/main.js +++ b/js/l3d/apps/prototype/tutorial/main.js @@ -36,7 +36,7 @@ function init() { scene = new THREE.Scene(); // Disable log for this time - BD.disable(); + L3D.BD.disable(); // Collidable objects to prevent camera from traversing objects var collidableObjects = []; @@ -52,7 +52,7 @@ function init() { renderer.setClearColor(0x87ceeb); // Initialize previewer - previewer = new Previewer(renderer, scene); + previewer = new L3D.Previewer(renderer, scene); previewer.domElement.style.position ="absolute"; previewer.domElement.style.cssFloat = 'top-left'; previewer.domElement.width = container_size.width(); @@ -67,12 +67,12 @@ function init() { var camera1 = new TutoCamera(50, container_size.width() / container_size.height(), 0.01, 100000, renderer, scene, onWindowResize, container_size, coins, container); // Initialize pointer for pointer lock - var pointer = new MousePointer(camera1); + var pointer = new L3D.MousePointer(camera1); pointer.domElement.width = container_size.width(); pointer.domElement.height = container_size.height(); // - var startCanvas = new StartCanvas(camera1); + var startCanvas = new L3D.StartCanvas(camera1); startCanvas.domElement.width = container_size.width(); startCanvas.domElement.height = container_size.height(); startCanvas.render(); @@ -88,11 +88,11 @@ function init() { // Initialize pointer camera tutorial = camera1.tutorial; - cameras = new CameraContainer(camera1, []); + cameras = new L3D.CameraContainer(camera1, []); tutorial.setCameras(cameras); // Load peach scene - initPeach(camera1, scene); + L3D.initPeach(camera1, scene); initListeners(); @@ -124,7 +124,7 @@ function initListeners() { buttonManager = new ButtonManager(cameras, previewer); // Camera selecter for hover and clicking recommendations - cameraSelecter = new CameraSelecter(renderer, scene, cameras, coins, buttonManager); + cameraSelecter = new L3D.CameraSelecter(renderer, scene, cameras, coins, buttonManager); } @@ -134,7 +134,7 @@ function render() { // Update recommendations (set raycastable if shown) var transform = buttonManager.showArrows ? show : hide; cameras.map(function(camera) { - if (camera instanceof RecommendedCamera) { + if (camera instanceof Recommendation) { transform(camera); camera.traverse(function(elt) { @@ -168,7 +168,7 @@ function render() { previewer.clear(); // Hide arrows in recommendation - cameras.map(function(camera) { if (camera instanceof RecommendedCamera) hide(camera); }); + cameras.map(function(camera) { if (camera instanceof Recommendation) hide(camera); }); // Render preview previewer.render(cameraSelecter.prev, container_size.width(), container_size.height()); diff --git a/js/l3d/apps/stream-demo/main.js b/js/l3d/apps/stream-demo/main.js index 77e2b19..f2b44e8 100644 --- a/js/l3d/apps/stream-demo/main.js +++ b/js/l3d/apps/stream-demo/main.js @@ -38,18 +38,18 @@ function init() { scene.add(ambient_light); // on initialise la camera que l’on place ensuite sur la scène - camera = new Camera(50, container_size.width / container_size.height, 1, 100000); + camera = new L3D.Camera(50, container_size.width / container_size.height, 1, 100000); scene.add(camera); window.addEventListener('resize', onWindowResize, false); // Load the scene // loader = new THREE.OBJLoader(); - sphereLoader = new ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene, null); + sphereLoader = new L3D.ProgressiveLoaderGeometry('/static/data/spheres/' + params.get.res + '.obj', scene, null); sphereLoader.load(); sphere = sphereLoader.obj; - plane = new Plane(1000,1000); + plane = new L3D.Plane(1000,1000); plane.translate(0,0,-100); plane.addToScene(scene); diff --git a/js/l3d/src/cameras/Camera.js b/js/l3d/src/cameras/Camera.js index bc059bb..6500d9d 100644 --- a/js/l3d/src/cameras/Camera.js +++ b/js/l3d/src/cameras/Camera.js @@ -1,31 +1,30 @@ -// class camera extends THREE.PerspectiveCamera -var Camera = function() { +L3D.Camera = function() { THREE.PerspectiveCamera.apply(this, arguments); this.theta = 0; - this.position.x = Camera.DISTANCE_X; - this.position.z = Camera.DISTANCE_Z; + this.position.x = L3D.Camera.DISTANCE_X; + this.position.z = L3D.Camera.DISTANCE_Z; this.up = new THREE.Vector3(0,0,1); this.target = new THREE.Vector3(); }; -Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype); +L3D.Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype); // Update function -Camera.prototype.update = function(time) { +L3D.Camera.prototype.update = function(time) { if (time === undefined) { time = 20; } this.theta += 0.01 * time / 20; - this.position.x = Camera.DISTANCE_X*Math.cos(this.theta); - this.position.y = Camera.DISTANCE_X*Math.sin(this.theta); + this.position.x = L3D.Camera.DISTANCE_X*Math.cos(this.theta); + this.position.y = L3D.Camera.DISTANCE_X*Math.sin(this.theta); }; // Look function -Camera.prototype.look = function() { +L3D.Camera.prototype.look = function() { this.lookAt(this.target); }; // Static members -Camera.DISTANCE_X = 1000; -Camera.DISTANCE_Z = 300; +L3D.Camera.DISTANCE_X = 1000; +L3D.Camera.DISTANCE_Z = 300; diff --git a/js/l3d/src/cameras/CameraContainer.js b/js/l3d/src/cameras/CameraContainer.js index bd6e2cb..ec06858 100644 --- a/js/l3d/src/cameras/CameraContainer.js +++ b/js/l3d/src/cameras/CameraContainer.js @@ -1,4 +1,4 @@ -var CameraContainer = function (pointerCamera, cameras) { +L3D.CameraContainer = function (pointerCamera, cameras) { if (cameras !== undefined) { this.cameras = cameras; } else { @@ -10,7 +10,7 @@ var CameraContainer = function (pointerCamera, cameras) { } }; -CameraContainer.prototype.mainCamera = function(id) { +L3D.CameraContainer.prototype.mainCamera = function(id) { if (id === undefined) { return this.pointerCamera; } @@ -22,35 +22,35 @@ CameraContainer.prototype.mainCamera = function(id) { this.current_camera = id; }; -CameraContainer.prototype.forEach = function(callback) { +L3D.CameraContainer.prototype.forEach = function(callback) { callback(this.pointerCamera); this.cameras.forEach(callback); }; -CameraContainer.prototype.look = function() { +L3D.CameraContainer.prototype.look = function() { this.mainCamera().look(); }; -CameraContainer.prototype.updateMainCamera = function(time) { +L3D.CameraContainer.prototype.updateMainCamera = function(time) { this.pointerCamera.update(time); }; -CameraContainer.prototype.update = function(position) { +L3D.CameraContainer.prototype.update = function(position) { this.cameras.map(function (elt) { elt.update(position); }); }; -CameraContainer.prototype.push = function(camera) { +L3D.CameraContainer.prototype.push = function(camera) { this.pointerCamera = camera; this.push = function(camera) { this.cameras.push(camera); }; }; -CameraContainer.prototype.get = function(i) { +L3D.CameraContainer.prototype.get = function(i) { return this.cameras[i]; }; -CameraContainer.prototype.getByObject = function(object) { +L3D.CameraContainer.prototype.getByObject = function(object) { for (var i in this.cameras) { if (this.cameras[i].containsObject(object)) { return this.get(i); @@ -58,20 +58,20 @@ CameraContainer.prototype.getByObject = function(object) { } }; -CameraContainer.prototype.setById = function(id) { +L3D.CameraContainer.prototype.setById = function(id) { var i = this.getById(id); if (i !== -1) this.current_camera = i; }; -CameraContainer.prototype.nextCamera = function() { +L3D.CameraContainer.prototype.nextCamera = function() { if (this.cameras.length !== 0) { this.current_camera++; this.current_camera%=this.cameras.length; } }; -CameraContainer.prototype.map = function(callback) { +L3D.CameraContainer.prototype.map = function(callback) { this.cameras.map(callback); }; diff --git a/js/l3d/src/cameras/PointerCamera.js b/js/l3d/src/cameras/PointerCamera.js index 49fa8da..866f66d 100644 --- a/js/l3d/src/cameras/PointerCamera.js +++ b/js/l3d/src/cameras/PointerCamera.js @@ -3,7 +3,7 @@ * @constructor * @augments THREE.PerspectiveCamera */ -var PointerCamera = function() { +L3D.PointerCamera = function() { THREE.PerspectiveCamera.apply(this, arguments); /** @@ -115,9 +115,9 @@ var PointerCamera = function() { /** * History of the moves of the camera - * @type {History} + * @type {L3D.History} */ - this.history = new History(); + this.history = new L3D.History(); /** * Option to enable or disable the pointer lock @@ -176,16 +176,16 @@ var PointerCamera = function() { * The camera we will move to when we'll reset the camera * @param {Object} */ - this.resetElements = resetBobombElements(); + this.resetElements = {position: new THREE.Vector3(0,1,1), target: new THREE.Vector3()}; }; -PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); -PointerCamera.prototype.constructor = PointerCamera; +L3D.PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); +L3D.PointerCamera.prototype.constructor = L3D.PointerCamera; /** * Locks the pointer inside the canvas, and displays a gun sight at the middle of the renderer * This method works only if the browser supports requestPointerLock */ -PointerCamera.prototype.lockPointer = function() { +L3D.PointerCamera.prototype.lockPointer = function() { if (this.shouldLock) { this.renderer.domElement.requestPointerLock = @@ -207,7 +207,7 @@ PointerCamera.prototype.lockPointer = function() { * Check that the pointer is locked or not, and updated locked attribute * @returns true if the pointer is locked, false otherwise */ -PointerCamera.prototype.isLocked = function() { +L3D.PointerCamera.prototype.isLocked = function() { var toto = document.pointerLockElement === this.renderer.domElement || document.mozPointerLockElement === this.renderer.domElement || @@ -220,7 +220,7 @@ PointerCamera.prototype.isLocked = function() { /** * Update the camera when the pointer lock changes state */ -PointerCamera.prototype.onPointerLockChange = function() { +L3D.PointerCamera.prototype.onPointerLockChange = function() { if (this.isLocked()) { @@ -259,7 +259,7 @@ PointerCamera.prototype.onPointerLockChange = function() { * Update the position of the camera * @param {Number} time number of milliseconds between the previous and the next frame */ -PointerCamera.prototype.update = function(time) { +L3D.PointerCamera.prototype.update = function(time) { if (this.moving) { this.linearMotion(time); } else if (this.movingHermite) { @@ -273,15 +273,15 @@ PointerCamera.prototype.update = function(time) { * Update the camera according to its linear motion * @param {Number} time number of milliseconds between the previous and the next frame */ -PointerCamera.prototype.linearMotion = function(time) { - var position_direction = Tools.diff(this.new_position, this.position); - var target_direction = Tools.diff(this.new_target, this.target); +L3D.PointerCamera.prototype.linearMotion = function(time) { + var position_direction = L3D.Tools.diff(this.new_position, this.position); + var target_direction = L3D.Tools.diff(this.new_target, this.target); - this.position.add(Tools.mul(position_direction, 0.05 * time / 20)); - this.target.add(Tools.mul(target_direction, 0.05 * time / 20)); + this.position.add(L3D.Tools.mul(position_direction, 0.05 * time / 20)); + this.target.add(L3D.Tools.mul(target_direction, 0.05 * time / 20)); - if (Tools.norm2(Tools.diff(this.position, this.new_position)) < 0.01 && - Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.01) { + if (L3D.Tools.norm2(L3D.Tools.diff(this.position, this.new_position)) < 0.01 && + L3D.Tools.norm2(L3D.Tools.diff(this.target, this.new_target)) < 0.01) { this.moving = false; this.anglesFromVectors(); } @@ -291,13 +291,13 @@ PointerCamera.prototype.linearMotion = function(time) { * Update the camera according to its hermite motion * @param {Number} time number of milliseconds between the previous and the next frame */ -PointerCamera.prototype.hermiteMotion = function(time) { +L3D.PointerCamera.prototype.hermiteMotion = function(time) { var e = this.hermitePosition.eval(this.t); this.position.x = e.x; this.position.y = e.y; this.position.z = e.z; - this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t)); + this.target = L3D.Tools.sum(this.position, this.hermiteAngles.eval(this.t)); this.t += 0.01 * time / 20; @@ -311,7 +311,7 @@ PointerCamera.prototype.hermiteMotion = function(time) { * Update the camera according to the user's input * @param {Number} time number of milliseconds between the previous and the next frame */ -PointerCamera.prototype.normalMotion = function(time) { +L3D.PointerCamera.prototype.normalMotion = function(time) { // Update angles if (this.motion.increasePhi) {this.phi += this.sensitivity * time / 20; this.changed = true; } @@ -340,7 +340,7 @@ PointerCamera.prototype.normalMotion = function(time) { self.shouldLogCameraAngles = true; }, 100); - var event = new BD.Event.KeyboardEvent(); + var event = new L3D.BD.Event.KeyboardEvent(); event.camera = this; } @@ -367,10 +367,10 @@ PointerCamera.prototype.normalMotion = function(time) { var direction = new THREE.Vector3(); if (this.motion.boost) speed *= 10; - if (this.motion.moveForward) {direction.add(Tools.mul(forward, speed)); this.changed = true;} - if (this.motion.moveBackward) {direction.sub(Tools.mul(forward, speed)); this.changed = true;} - if (this.motion.moveLeft) {direction.add(Tools.mul(left, speed)); this.changed = true;} - if (this.motion.moveRight) {direction.sub(Tools.mul(left, speed)); this.changed = true;} + if (this.motion.moveForward) {direction.add(L3D.Tools.mul(forward, speed)); this.changed = true;} + if (this.motion.moveBackward) {direction.sub(L3D.Tools.mul(forward, speed)); this.changed = true;} + if (this.motion.moveLeft) {direction.add(L3D.Tools.mul(left, speed)); this.changed = true;} + if (this.motion.moveRight) {direction.sub(L3D.Tools.mul(left, speed)); this.changed = true;} if (!this.collisions || !this.isColliding(direction)) { this.position.add(direction); @@ -384,17 +384,17 @@ PointerCamera.prototype.normalMotion = function(time) { /** * Reset the camera to its resetElements, and finishes any motion */ -PointerCamera.prototype.reset = function() { +L3D.PointerCamera.prototype.reset = function() { this.resetPosition(); this.moving = false; this.movingHermite = false; - (new BD.Event.ResetClicked()).send(); + (new L3D.BD.Event.ResetClicked()).send(); }; /** * Reset the position of th camera */ -PointerCamera.prototype.resetPosition = function() { +L3D.PointerCamera.prototype.resetPosition = function() { this.position.copy(this.resetElements.position); this.target.copy(this.resetElements.target); this.anglesFromVectors(); @@ -403,7 +403,7 @@ PointerCamera.prototype.resetPosition = function() { /** * Computes the vectors (forward, left, ...) according to theta and phi */ -PointerCamera.prototype.vectorsFromAngles = function() { +L3D.PointerCamera.prototype.vectorsFromAngles = function() { // Update direction this.forward.y = Math.sin(this.phi); @@ -417,8 +417,8 @@ PointerCamera.prototype.vectorsFromAngles = function() { /** * Computes theta and phi according to the vectors (forward, left, ...) */ -PointerCamera.prototype.anglesFromVectors = function() { - var forward = Tools.diff(this.target, this.position); +L3D.PointerCamera.prototype.anglesFromVectors = function() { + var forward = L3D.Tools.diff(this.target, this.position); forward.normalize(); this.phi = Math.asin(forward.y); @@ -433,7 +433,7 @@ PointerCamera.prototype.anglesFromVectors = function() { * @param {Camera} camera Camera to move to * @param {Boolean} [toSave=true] true if you want to save the current state of the camera */ -PointerCamera.prototype.move = function(otherCamera, toSave) { +L3D.PointerCamera.prototype.move = function(otherCamera, toSave) { if (toSave === undefined) toSave = true; @@ -442,8 +442,8 @@ PointerCamera.prototype.move = function(otherCamera, toSave) { this.new_position = otherCamera.position.clone(); var t = [0,1]; var f = [this.position.clone(), this.new_position]; - var fp = [Tools.diff(this.target, this.position), Tools.diff(this.new_target, this.new_position)]; - this.hermite = new Hermite.Polynom(t,f,fp); + var fp = [L3D.Tools.diff(this.target, this.position), L3D.Tools.diff(this.new_target, this.new_position)]; + this.hermite = new L3D.Hermite.Polynom(t,f,fp); this.t = 0; if (toSave) { @@ -460,22 +460,22 @@ PointerCamera.prototype.move = function(otherCamera, toSave) { * @param {Camera} camera Camera to move to * @param {Boolean} [toSave=true] true if you want to save the current state of the camera */ -PointerCamera.prototype.moveHermite = function(otherCamera, toSave) { +L3D.PointerCamera.prototype.moveHermite = function(otherCamera, toSave) { if (toSave === undefined) toSave = true; this.movingHermite = true; this.t = 0; - this.hermitePosition = new Hermite.special.Polynom( + this.hermitePosition = new L3D.Hermite.special.Polynom( this.position.clone(), otherCamera.position.clone(), - Tools.mul(Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) + L3D.Tools.mul(L3D.Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) ); - this.hermiteAngles = new Hermite.special.Polynom( - Tools.diff(this.target, this.position), - Tools.diff(otherCamera.target, otherCamera.position), + this.hermiteAngles = new L3D.Hermite.special.Polynom( + L3D.Tools.diff(this.target, this.position), + L3D.Tools.diff(otherCamera.target, otherCamera.position), new THREE.Vector3() ); @@ -493,12 +493,12 @@ PointerCamera.prototype.moveHermite = function(otherCamera, toSave) { * @param {THREE.Vector3} direction the direction of the camera * @returns {Boolean} true if there is a collision, false otherwise */ -PointerCamera.prototype.isColliding = function(direction) { +L3D.PointerCamera.prototype.isColliding = function(direction) { 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 && + if (intersects[i].distance < L3D.Tools.norm(direction) + this.speed * 300 && intersects[i].object.raycastable) { return true; } @@ -510,14 +510,14 @@ PointerCamera.prototype.isColliding = function(direction) { /** * Look method. Equivalent to gluLookAt for the current camera */ -PointerCamera.prototype.look = function() { +L3D.PointerCamera.prototype.look = function() { this.lookAt(this.target); }; /** * Adds the camera to the scene */ -PointerCamera.prototype.addToScene = function(scene) { +L3D.PointerCamera.prototype.addToScene = function(scene) { scene.add(this); }; @@ -526,7 +526,7 @@ PointerCamera.prototype.addToScene = function(scene) { * @param {event} event the event that happened * @param {Booelean} toSet true if the key was pressed, false if released */ -PointerCamera.prototype.onKeyEvent = function(event, toSet) { +L3D.PointerCamera.prototype.onKeyEvent = function(event, toSet) { // Create copy of state var motionJsonCopy = JSON.stringify(this.motion); @@ -553,7 +553,7 @@ PointerCamera.prototype.onKeyEvent = function(event, toSet) { } if (motionJsonCopy != JSON.stringify(this.motion)) { // Log any change - var e = new BD.Event.KeyboardEvent(); + var e = new L3D.BD.Event.KeyboardEvent(); e.camera = this; e.send(); } @@ -563,7 +563,7 @@ PointerCamera.prototype.onKeyEvent = function(event, toSet) { * Manages the key pressed events * @param {event} event the event to manage */ -PointerCamera.prototype.onKeyDown = function(event) { +L3D.PointerCamera.prototype.onKeyDown = function(event) { this.onKeyEvent(event, true); }; @@ -571,7 +571,7 @@ PointerCamera.prototype.onKeyDown = function(event) { * Manages the key released events * @param {event} event the event to manage */ -PointerCamera.prototype.onKeyUp = function(event) { +L3D.PointerCamera.prototype.onKeyUp = function(event) { this.onKeyEvent(event, false); }; @@ -579,7 +579,7 @@ PointerCamera.prototype.onKeyUp = function(event) { * Manages the mouse down events. Start drag'n'dropping if the options are set to drag'n'drop * @param {event} event the event to manage */ -PointerCamera.prototype.onMouseDown = function(event) { +L3D.PointerCamera.prototype.onMouseDown = function(event) { if (!this.shouldLock) { @@ -595,7 +595,7 @@ PointerCamera.prototype.onMouseDown = function(event) { * Manages the mouse move events. Modifies the target of the camera according to the drag'n'drop motion * @param {event} event the event to manage */ -PointerCamera.prototype.onMouseMove = function(event) { +L3D.PointerCamera.prototype.onMouseMove = function(event) { if (!this.shouldLock && this.dragging) { var mouse = {x: this.mouse.x, y: this.mouse.y}; @@ -613,7 +613,7 @@ PointerCamera.prototype.onMouseMove = function(event) { * Manages the mouse move envent in case of pointer lock * @param {event} event the event to manage */ -PointerCamera.prototype.onMouseMovePointer = function(e) { +L3D.PointerCamera.prototype.onMouseMovePointer = function(e) { if (this.isLocked()) { @@ -637,12 +637,12 @@ PointerCamera.prototype.onMouseMovePointer = function(e) { * Manages the mouse up event. Stops the dragging * @param {event} event the event to manage */ -PointerCamera.prototype.onMouseUp = function(event) { +L3D.PointerCamera.prototype.onMouseUp = function(event) { this.onMouseMove(event); // Send log to DB if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) { - var e = new BD.Event.KeyboardEvent(); + var e = new L3D.BD.Event.KeyboardEvent(); e.camera = this; e.send(); } @@ -653,7 +653,7 @@ PointerCamera.prototype.onMouseUp = function(event) { /** * Logs the camera to the terminal (pratical to create recommended views) */ -PointerCamera.prototype.log = function() { +L3D.PointerCamera.prototype.log = function() { console.log("createCamera(\nnew THREE.Vector3(" + this.position.x + "," + this.position.y + ',' + this.position.z + '),\n' + "new THREE.Vector3(" + this.target.x + "," + this.target.y + ',' + this.target.z + ')\n)'); }; @@ -661,7 +661,7 @@ PointerCamera.prototype.log = function() { /** * Save the current state of the camera in the history */ -PointerCamera.prototype.save = function() { +L3D.PointerCamera.prototype.save = function() { var backup = {}; backup.position = this.position.clone(); backup.target = this.target.clone(); @@ -671,10 +671,10 @@ PointerCamera.prototype.save = function() { /** * Undo last motion according to the history */ -PointerCamera.prototype.undo = function() { +L3D.PointerCamera.prototype.undo = function() { var move = this.history.undo(); if (move !== undefined) { - var event = new BD.Event.PreviousNextClicked(); + var event = new L3D.BD.Event.PreviousNextClicked(); event.previous = true; event.camera = move; event.send(); @@ -686,10 +686,10 @@ PointerCamera.prototype.undo = function() { /** * Redo last motion according to the history */ -PointerCamera.prototype.redo = function() { +L3D.PointerCamera.prototype.redo = function() { var move = this.history.redo(); if (move !== undefined) { - var event = new BD.Event.PreviousNextClicked(); + var event = new L3D.BD.Event.PreviousNextClicked(); event.previous = false; event.camera = move; event.send(); @@ -702,7 +702,7 @@ PointerCamera.prototype.redo = function() { * Checks if there is a undo possibility in the history * @returns {Boolean} true if undo is possible, false otherwise */ -PointerCamera.prototype.undoable = function() { +L3D.PointerCamera.prototype.undoable = function() { return this.history.undoable(); }; @@ -710,11 +710,11 @@ PointerCamera.prototype.undoable = function() { * Checks if there is a redo possibility in the history * @returns {Boolean} true if redo is possible, false otherwise */ -PointerCamera.prototype.redoable = function() { +L3D.PointerCamera.prototype.redoable = function() { return this.history.redoable(); }; -PointerCamera.prototype.toList = function() { +L3D.PointerCamera.prototype.toList = function() { this.updateMatrix(); this.updateMatrixWorld(); diff --git a/js/l3d/src/cameras/ReplayCamera.js b/js/l3d/src/cameras/ReplayCamera.js index cc530ee..78e2716 100644 --- a/js/l3d/src/cameras/ReplayCamera.js +++ b/js/l3d/src/cameras/ReplayCamera.js @@ -1,5 +1,5 @@ // class camera extends THREE.PerspectiveCamera -var ReplayCamera = function() { +L3D.ReplayCamera = function() { THREE.PerspectiveCamera.apply(this, arguments); this.coins = arguments[4]; @@ -31,18 +31,16 @@ var ReplayCamera = function() { this.theta = Math.PI; this.phi = Math.PI; - this.resetElements = resetBobombElements(); - }; -ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); -ReplayCamera.prototype.constructor = ReplayCamera; +L3D.ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); +L3D.ReplayCamera.prototype.constructor = L3D.ReplayCamera; -ReplayCamera.prototype.look = function() { +L3D.ReplayCamera.prototype.look = function() { this.lookAt(this.target); }; // Update function -ReplayCamera.prototype.update = function(time) { +L3D.ReplayCamera.prototype.update = function(time) { if (this.started) { if (this.event.type == 'camera') { this.cameraMotion(time); @@ -59,8 +57,8 @@ ReplayCamera.prototype.update = function(time) { } }; -ReplayCamera.prototype.linearMotion = function(time) { - var tmp = Tools.sum(Tools.mul(this.old_position, 1-this.t), Tools.mul(this.new_position, this.t)); +L3D.ReplayCamera.prototype.linearMotion = function(time) { + var tmp = L3D.Tools.sum(L3D.Tools.mul(this.old_position, 1-this.t), L3D.Tools.mul(this.new_position, this.t)); this.position.x = tmp.x; this.position.y = tmp.y; this.position.z = tmp.z; @@ -71,13 +69,13 @@ ReplayCamera.prototype.linearMotion = function(time) { } }; -ReplayCamera.prototype.cameraMotion = function(time) { +L3D.ReplayCamera.prototype.cameraMotion = function(time) { - var tmp = Tools.sum(Tools.mul(this.old_position, 1-this.t), Tools.mul(this.new_position, this.t)); + var tmp = L3D.Tools.sum(L3D.Tools.mul(this.old_position, 1-this.t), L3D.Tools.mul(this.new_position, this.t)); this.position.x = tmp.x; this.position.y = tmp.y; this.position.z = tmp.z; - this.target = Tools.sum(Tools.mul(this.old_target, 1-this.t), Tools.mul(this.new_target, this.t)); + this.target = L3D.Tools.sum(L3D.Tools.mul(this.old_target, 1-this.t), L3D.Tools.mul(this.new_target, this.t)); this.t += 1 / (((new Date(this.path[this.counter].time)).getTime() - (new Date(this.path[this.counter-1].time)).getTime()) / 20); if (this.t > 1) { @@ -85,13 +83,13 @@ ReplayCamera.prototype.cameraMotion = function(time) { } }; -ReplayCamera.prototype.hermiteMotion = function(time) { +L3D.ReplayCamera.prototype.hermiteMotion = function(time) { var e = this.hermitePosition.eval(this.t); this.position.x = e.x; this.position.y = e.y; this.position.z = e.z; - this.target = Tools.sum(this.position, this.hermiteAngles.eval(this.t)); + this.target = L3D.Tools.sum(this.position, this.hermiteAngles.eval(this.t)); this.t += 0.01 * time / 20; @@ -100,7 +98,7 @@ ReplayCamera.prototype.hermiteMotion = function(time) { } }; -ReplayCamera.prototype.nextEvent = function() { +L3D.ReplayCamera.prototype.nextEvent = function() { this.counter++; // Finished @@ -137,19 +135,19 @@ ReplayCamera.prototype.nextEvent = function() { } }; -ReplayCamera.prototype.reset = function() { +L3D.ReplayCamera.prototype.reset = function() { this.resetPosition(); this.moving = false; this.movingHermite = false; }; -ReplayCamera.prototype.resetPosition = function() { +L3D.ReplayCamera.prototype.resetPosition = function() { this.position.copy(this.resetElements.position); this.target.copy(this.resetElements.target); this.anglesFromVectors(); }; -ReplayCamera.prototype.vectorsFromAngles = function() { +L3D.ReplayCamera.prototype.vectorsFromAngles = function() { // Update direction this.forward.y = Math.sin(this.phi); @@ -160,9 +158,9 @@ ReplayCamera.prototype.vectorsFromAngles = function() { }; -ReplayCamera.prototype.anglesFromVectors = function() { +L3D.ReplayCamera.prototype.anglesFromVectors = function() { // Update phi and theta so that return to reality does not hurt - var forward = Tools.diff(this.target, this.position); + var forward = L3D.Tools.diff(this.target, this.position); forward.normalize(); this.phi = Math.asin(forward.y); @@ -172,7 +170,7 @@ ReplayCamera.prototype.anglesFromVectors = function() { this.theta = Math.atan2(forward.x, forward.z); }; -ReplayCamera.prototype.move = function(otherCamera) { +L3D.ReplayCamera.prototype.move = function(otherCamera) { this.moving = true; this.old_target = this.target.clone(); this.old_position = this.position.clone(); @@ -182,21 +180,21 @@ ReplayCamera.prototype.move = function(otherCamera) { }; -ReplayCamera.prototype.moveHermite = function(otherCamera) { +L3D.ReplayCamera.prototype.moveHermite = function(otherCamera) { this.movingHermite = true; this.t = 0; - this.hermitePosition = new Hermite.special.Polynom( + this.hermitePosition = new L3D.Hermite.special.Polynom( this.position.clone(), otherCamera.position.clone(), - Tools.mul(Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) + L3D.Tools.mul(L3D.Tools.diff(otherCamera.target, otherCamera.position).normalize(),4) ); - this.hermiteAngles = new Hermite.special.Polynom( - Tools.diff(this.target, this.position), - Tools.diff(otherCamera.target, otherCamera.position), + this.hermiteAngles = new L3D.Hermite.special.Polynom( + L3D.Tools.diff(this.target, this.position), + L3D.Tools.diff(otherCamera.target, otherCamera.position), new THREE.Vector3() ); }; -ReplayCamera.prototype.save = function() {}; +L3D.ReplayCamera.prototype.save = function() {}; diff --git a/js/l3d/src/canvases/MousePointer.js b/js/l3d/src/canvases/MousePointer.js index b7f39b4..cb64426 100644 --- a/js/l3d/src/canvases/MousePointer.js +++ b/js/l3d/src/canvases/MousePointer.js @@ -1,4 +1,4 @@ -var MousePointer = function(camera) { +L3D.MousePointer = function(camera) { this.domElement = document.createElement('canvas'); this.domElement.style.position = 'absolute'; @@ -7,37 +7,37 @@ var MousePointer = function(camera) { this.size = 10; this.drawn = false; camera.mousePointer = this; - this.style = MousePointer.NONE; + this.style = L3D.MousePointer.NONE; }; -MousePointer.NONE = 0; -MousePointer.BLACK = 1; -MousePointer.RED = 2; +L3D.MousePointer.NONE = 0; +L3D.MousePointer.BLACK = 1; +L3D.MousePointer.RED = 2; -MousePointer.toColor = function(style) { +L3D.MousePointer.toColor = function(style) { switch (style) { - case MousePointer.NONE: + case L3D.MousePointer.NONE: return null; - case MousePointer.BLACK: + case L3D.MousePointer.BLACK: return '#000000'; - case MousePointer.RED: + case L3D.MousePointer.RED: return '#ff0000'; } }; -MousePointer.prototype.render = function(style) { +L3D.MousePointer.prototype.render = function(style) { if (this.style !== style) { - if (style === MousePointer.NONE) { + if (style === L3D.MousePointer.NONE) { // Clear canvas this.domElement.width = this.domElement.width; - this.style = MousePointer.NONE; + this.style = L3D.MousePointer.NONE; } else { @@ -64,7 +64,7 @@ MousePointer.prototype.render = function(style) { this.ctx.stroke(); this.ctx.lineWidth = 2; - this.ctx.strokeStyle = MousePointer.toColor(style); + this.ctx.strokeStyle = L3D.MousePointer.toColor(style); this.ctx.stroke(); this.style = style; @@ -75,8 +75,8 @@ MousePointer.prototype.render = function(style) { }; -MousePointer.prototype.clear = function() { +L3D.MousePointer.prototype.clear = function() { - this.render(MousePointer.NONE); + this.render(L3D.MousePointer.NONE); }; diff --git a/js/l3d/src/canvases/Previewer.js b/js/l3d/src/canvases/Previewer.js index c1f82c3..8464b29 100644 --- a/js/l3d/src/canvases/Previewer.js +++ b/js/l3d/src/canvases/Previewer.js @@ -2,7 +2,7 @@ Math.clamp = Math.clamp || function(number, min, max) { return Math.max(Math.min(number, max), min); }; -var Previewer = function(renderer, scene) { +L3D.Previewer = function(renderer, scene) { this.domElement = document.createElement('canvas'); this.ctx = this.domElement.getContext('2d'); this.renderer = renderer; @@ -12,7 +12,7 @@ var Previewer = function(renderer, scene) { this.drawnBefore = false; }; -Previewer.prototype.render = function(prev, container_width, container_height) { +L3D.Previewer.prototype.render = function(prev, container_width, container_height) { var width, height, left, bottom; if (prev.go) { @@ -79,18 +79,18 @@ Previewer.prototype.render = function(prev, container_width, container_height) { }; -Previewer.prototype.clear = function() { +L3D.Previewer.prototype.clear = function() { if (this.clearNeeded) { this.domElement.width = this.domElement.width; this.clearNeeded = false; } }; -Previewer.prototype.fixedRecommendation = function(bool) { +L3D.Previewer.prototype.fixedRecommendation = function(bool) { this.fixed = bool; }; -Previewer.prototype.update = function(arg) { +L3D.Previewer.prototype.update = function(arg) { this.drawnBefore = this.drawn; this.drawn = arg; }; diff --git a/js/l3d/src/canvases/StartCanvas.js b/js/l3d/src/canvases/StartCanvas.js index 5502cca..78d00f6 100644 --- a/js/l3d/src/canvases/StartCanvas.js +++ b/js/l3d/src/canvases/StartCanvas.js @@ -1,4 +1,4 @@ -var StartCanvas = function(camera) { +L3D.StartCanvas = function(camera) { this.domElement = document.createElement('canvas'); this.domElement.style.position = 'absolute'; @@ -10,7 +10,7 @@ var StartCanvas = function(camera) { }; -StartCanvas.prototype.render = function() { +L3D.StartCanvas.prototype.render = function() { if (!this.shown) { @@ -30,7 +30,7 @@ StartCanvas.prototype.render = function() { }; -StartCanvas.prototype.clear = function() { +L3D.StartCanvas.prototype.clear = function() { if (this.shown) { diff --git a/js/l3d/src/loaders/ProgressiveLoader.js b/js/l3d/src/loaders/ProgressiveLoader.js index 93ba00d..2bfd567 100644 --- a/js/l3d/src/loaders/ProgressiveLoader.js +++ b/js/l3d/src/loaders/ProgressiveLoader.js @@ -1,4 +1,4 @@ -var _parseList = function(arr) { +L3D._parseList = function(arr) { var ret = {}; ret.index = arr[1]; @@ -63,7 +63,7 @@ var _parseList = function(arr) { return ret; }; -var ProgressiveLoader = function(path, scene, camera, callback) { +L3D.ProgressiveLoader = function(path, scene, camera, callback) { // Init attributes this.objPath = path.substring(1, path.length); this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/'; @@ -91,7 +91,7 @@ var ProgressiveLoader = function(path, scene, camera, callback) { }; -ProgressiveLoader.prototype.load = function() { +L3D.ProgressiveLoader.prototype.load = function() { var self = this; @@ -106,7 +106,7 @@ ProgressiveLoader.prototype.load = function() { }); }; -ProgressiveLoader.prototype.initIOCallbacks = function() { +L3D.ProgressiveLoader.prototype.initIOCallbacks = function() { var self = this; @@ -280,7 +280,7 @@ ProgressiveLoader.prototype.initIOCallbacks = function() { }); }; -ProgressiveLoader.prototype.start = function() { +L3D.ProgressiveLoader.prototype.start = function() { this.socket.emit('request', this.objPath); }; diff --git a/js/l3d/src/loaders/ProgressiveLoaderGeometry.js b/js/l3d/src/loaders/ProgressiveLoaderGeometry.js index aacbf85..f60969f 100644 --- a/js/l3d/src/loaders/ProgressiveLoaderGeometry.js +++ b/js/l3d/src/loaders/ProgressiveLoaderGeometry.js @@ -2,7 +2,7 @@ * Parse a list as it is sent by the server and gives a slightly more comprehensible result * @private */ -var _parseList2 = function(arr) { +L3D._parseList2 = function(arr) { var ret = {}; ret.index = arr[1]; @@ -77,8 +77,9 @@ var _parseList2 = function(arr) { * order) * @param {function} callback callback to call on the objects when they're created * @constructor + * @memberOf L3D */ -var ProgressiveLoaderGeometry = function(path, scene, camera, callback) { +L3D.ProgressiveLoaderGeometry = function(path, scene, camera, callback) { /** * Path to the .obj file @@ -180,7 +181,7 @@ var ProgressiveLoaderGeometry = function(path, scene, camera, callback) { /** * Starts the loading of the mesh */ -ProgressiveLoaderGeometry.prototype.load = function() { +L3D.ProgressiveLoaderGeometry.prototype.load = function() { var self = this; @@ -198,7 +199,7 @@ ProgressiveLoaderGeometry.prototype.load = function() { /** * Will return a list representation of the camera (to be sent to the server) */ -ProgressiveLoaderGeometry.prototype.getCamera = function() { +L3D.ProgressiveLoaderGeometry.prototype.getCamera = function() { if (this.camera === null) return null; @@ -208,7 +209,7 @@ ProgressiveLoaderGeometry.prototype.getCamera = function() { /** * Initializes the socket.io functions so that it can discuss with the server */ -ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() { +L3D.ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() { var self = this; @@ -233,7 +234,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() { // console.log("Received elements for the " + (++self.counter) + "th time !"); for (var i = 0; i < arr.length; i++) { - var elt = _parseList2(arr[i]); + var elt = L3D._parseList2(arr[i]); // console.log(elts); if (elt.type === 'vertex') { @@ -371,7 +372,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() { /** * Starts the communication with the server */ -ProgressiveLoaderGeometry.prototype.start = function() { +L3D.ProgressiveLoaderGeometry.prototype.start = function() { this.socket.emit('request', this.objPath); }; diff --git a/js/l3d/src/math/Hermite.js b/js/l3d/src/math/Hermite.js index 0972e2b..f0e0c73 100644 --- a/js/l3d/src/math/Hermite.js +++ b/js/l3d/src/math/Hermite.js @@ -1,6 +1,6 @@ -var Hermite = {}; +L3D.Hermite = {}; -Hermite.Polynom = function(t, f, fp) { +L3D.Hermite.Polynom = function(t, f, fp) { this.times = t; this.evals = f; this.primes = fp; @@ -8,15 +8,15 @@ Hermite.Polynom = function(t, f, fp) { this.baseFunctions = []; for (var i in this.times) { - this.baseFunctions.push(new Hermite.BaseFunction(i, this.times)); + this.baseFunctions.push(new L3D.Hermite.BaseFunction(i, this.times)); } // Let's do something at least a little reusable this.tools = {}; if (f[0] instanceof THREE.Vector3) { this.tools.whatType = 'THREE.Vector3'; - this.tools.sum = Tools.sum; - this.tools.prod = Tools.mul; + this.tools.sum = L3D.Tools.sum; + this.tools.prod = L3D.Tools.mul; } else { this.tools.whatType = 'number'; this.tools.sum = function(a, b) { return a + b; }; @@ -24,7 +24,7 @@ Hermite.Polynom = function(t, f, fp) { } }; -Hermite.Polynom.prototype.eval = function(t) { +L3D.Hermite.Polynom.prototype.eval = function(t) { var ret; if (this.tools.whatType === 'THREE.Vector3') { @@ -67,7 +67,7 @@ Hermite.Polynom.prototype.eval = function(t) { return ret; }; -Hermite.Polynom.prototype.prime = function(t) { +L3D.Hermite.Polynom.prototype.prime = function(t) { var ret; if (this.tools.whatType === 'THREE.Vector3') { @@ -141,12 +141,12 @@ Hermite.Polynom.prototype.prime = function(t) { return ret; }; -Hermite.BaseFunction = function(index, times) { +L3D.Hermite.BaseFunction = function(index, times) { this.index = index; this.times = times; }; -Hermite.BaseFunction.prototype.eval = function(t) { +L3D.Hermite.BaseFunction.prototype.eval = function(t) { var ret = 1; for (var i in this.times) { @@ -158,7 +158,7 @@ Hermite.BaseFunction.prototype.eval = function(t) { return ret * ret; }; -Hermite.BaseFunction.prototype.prime = function(t) { +L3D.Hermite.BaseFunction.prototype.prime = function(t) { var ret = 0; for (var i in this.times) { @@ -170,16 +170,16 @@ Hermite.BaseFunction.prototype.prime = function(t) { return this.eval(t) * ret; }; -Hermite.special = {}; +L3D.Hermite.special = {}; // This polynom interpolates with two coords and one derivative // t = [0,1] -Hermite.special.Polynom = function(P0, P1, PP1) { +L3D.Hermite.special.Polynom = function(P0, P1, PP1) { this.tools = {}; if (P0 instanceof THREE.Vector3) { - this.tools.sum = Tools.sum; - this.tools.mul = Tools.mul; - this.tools.diff = Tools.diff; + this.tools.sum = L3D.Tools.sum; + this.tools.mul = L3D.Tools.mul; + this.tools.diff = L3D.Tools.diff; this.c = P0.clone(); } else { this.tools.sum = function(a,b) { return a+b; }; @@ -192,10 +192,10 @@ Hermite.special.Polynom = function(P0, P1, PP1) { this.b = this.tools.diff(this.tools.mul(this.tools.diff(P1,P0), 2), PP1); }; -Hermite.special.Polynom.prototype.eval = function(t) { +L3D.Hermite.special.Polynom.prototype.eval = function(t) { return this.tools.sum(this.tools.mul(this.a, t*t), this.tools.sum(this.tools.mul(this.b, t), this.c)); }; -Hermite.special.Polynom.prototype.prime = function(t) { +L3D.Hermite.special.Polynom.prototype.prime = function(t) { return this.tools.sum(this.tools.mul(this.a,2*t), this.b); }; diff --git a/js/l3d/src/math/HermiteTest/HermiteTest.js b/js/l3d/src/math/HermiteTest.js similarity index 100% rename from js/l3d/src/math/HermiteTest/HermiteTest.js rename to js/l3d/src/math/HermiteTest.js diff --git a/js/l3d/src/math/Tools.js b/js/l3d/src/math/Tools.js index 6664812..4fd5b5b 100644 --- a/js/l3d/src/math/Tools.js +++ b/js/l3d/src/math/Tools.js @@ -1,18 +1,18 @@ -var Tools = {version : "1.0" }; +L3D.Tools = {}; -Tools.sum = function(v1, v2) { +L3D.Tools.sum = function(v1, v2) { return new THREE.Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); }; -Tools.diff = function(v1, v2) { +L3D.Tools.diff = function(v1, v2) { return new THREE.Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); }; -Tools.dot = function(v1, v2) { +L3D.Tools.dot = function(v1, v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; }; -Tools.cross = function(v1, v2) { +L3D.Tools.cross = function(v1, v2) { return new THREE.Vector3( v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, @@ -20,18 +20,18 @@ Tools.cross = function(v1, v2) { ); }; -Tools.mul = function(v1, lambda) { +L3D.Tools.mul = function(v1, lambda) { return new THREE.Vector3(v1.x * lambda, v1.y * lambda, v1.z * lambda); }; -Tools.equals = function(v1, v2) { +L3D.Tools.equals = function(v1, v2) { return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z; }; -Tools.norm2 = function(v) { +L3D.Tools.norm2 = function(v) { return v.x * v.x + v.y * v.y + v.z * v.z; }; -Tools.norm = function(v) { - return Math.sqrt(Tools.norm2(v)); +L3D.Tools.norm = function(v) { + return Math.sqrt(L3D.Tools.norm2(v)); }; diff --git a/js/l3d/src/math/ToolsTest.js b/js/l3d/src/math/ToolsTest.js index 1160b02..70e17fd 100644 --- a/js/l3d/src/math/ToolsTest.js +++ b/js/l3d/src/math/ToolsTest.js @@ -17,10 +17,10 @@ function main() { // First tests document.write("