Added namespaces

This commit is contained in:
Thomas FORGIONE 2015-07-01 16:31:43 +02:00
parent 5e0551179e
commit 9c7350d41b
38 changed files with 552 additions and 556 deletions

View File

@ -54,13 +54,13 @@ var generateSceneNumber = function(req, res) {
var sceneToFunction = function(scene) { var sceneToFunction = function(scene) {
switch (scene) { switch (scene) {
case 2: case 2:
return 'initBobomb'; return 'L3D.initBobomb';
case 3: case 3:
return 'initMountain'; return 'L3D.initMountain';
case 4: case 4:
return 'initWhomp'; return 'L3D.initWhomp';
default: default:
return 'initPeach'; return 'L3D.initPeach';
} }
}; };

View File

@ -4,7 +4,7 @@ block title
title #{title} - Prototype - Arrows title #{title} - Prototype - Arrows
block configjs block configjs
script RecommendedCamera = FixedCamera; script Recommendation = L3D.ArrowRecommendation;
//-block preciseDescription //-block preciseDescription
p p

View File

@ -4,7 +4,7 @@ block title
title #{title} - Prototype title #{title} - Prototype
block extrajs block extrajs
script RecommendedCamera = FixedCamera; script Recommendation = L3D.ArrowRecommendation;
script var params = params || {}; params.get = params.get || {}; params.get.id = #{id}; script var params = params || {}; params.get = params.get || {}; params.get.id = #{id};
script initMainScene = #{initjs} script initMainScene = #{initjs}
script(src="/static/js/replay.min.js") script(src="/static/js/replay.min.js")

View File

@ -4,7 +4,7 @@ block title
title #{title} - Prototype - Arrows title #{title} - Prototype - Arrows
block mainjs block mainjs
script initMainScene = initSponza script initMainScene = L3D.initSponza
script(src="/static/js/prototypeinteractive.min.js") script(src="/static/js/prototypeinteractive.min.js")
block configjs block configjs

View File

@ -7,7 +7,7 @@ block title
title #{title} - Prototype - Tutorial title #{title} - Prototype - Tutorial
block configjs block configjs
script RecommendedCamera = FixedCamera; script Recommendation = L3D.ArrowRecommendation;
script(src="/static/js/tutorial.min.js") script(src="/static/js/tutorial.min.js")
block fullscreen block fullscreen

View File

@ -10,9 +10,9 @@ all: L3D L3DP Socket Three Stats Bouncing Multisphere StreamingSimulator Prototy
L3D: L3D:
$(CLOSURE) $(OPT) \ $(CLOSURE) $(OPT) \
--js l3d/src/l3d.js \
--js l3d/src/math/Tools.js \ --js l3d/src/math/Tools.js \
--js l3d/src/math/Hermite.js \ --js l3d/src/math/Hermite.js \
--js l3d/src/utils/List.js \
--js l3d/src/utils/CameraSelecter.js \ --js l3d/src/utils/CameraSelecter.js \
--js l3d/src/utils/Logger.js \ --js l3d/src/utils/Logger.js \
--js l3d/src/utils/Objects.js \ --js l3d/src/utils/Objects.js \

View File

@ -1,12 +1,12 @@
var BouncingCube = function(size, style) { var BouncingCube = function(size, style) {
Cube.call(this, size, style); L3D.Cube.call(this, size, style);
this.fixed_center = new THREE.Vector3(); this.fixed_center = new THREE.Vector3();
this.center = new THREE.Vector3(); this.center = new THREE.Vector3();
this.speed = new THREE.Vector3(0,0,300); 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.constructor = BouncingCube;
BouncingCube.prototype.update = function() { BouncingCube.prototype.update = function() {

View File

@ -33,7 +33,7 @@ function init() {
scene.add(ambient_light); scene.add(ambient_light);
// on initialise la camera que lon place ensuite sur la scène // on initialise la camera que lon 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); scene.add(camera);
window.addEventListener('resize', onWindowResize, false); 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 lajoute à la scène // on créé un cube au quel on définie un matériau puis on lajoute à la scène
cube = new BouncingCube(200, {color: "red"}); cube = new BouncingCube(200, {color: "red"});
plane = new Plane(1000,1000); plane = new L3D.Plane(1000,1000);
plane.translate(0,0,-100); plane.translate(0,0,-100);
cube.addToScene(scene); cube.addToScene(scene);

View File

@ -55,7 +55,7 @@ function init() {
scene.add(ambient_light); scene.add(ambient_light);
// on initialise la camera que lon place ensuite sur la scène // on initialise la camera que lon 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); scene.add(camera);
window.addEventListener('resize', onWindowResize, false); window.addEventListener('resize', onWindowResize, false);
@ -71,8 +71,7 @@ function init() {
} }
plane = new L3D.Plane(1000,1000);
plane = new Plane(1000,1000);
plane.translate(0,0,-100); plane.translate(0,0,-100);
plane.addToScene(scene); plane.addToScene(scene);
} }

View File

@ -44,7 +44,7 @@ var previousTime;
window.onbeforeunload = function() { 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 !'; return 'Warning : you are going to leave the page and abort the current test !';
@ -54,7 +54,7 @@ window.onbeforeunload = function() {
init(); init();
if (initMainScene !== initPeach && initMainScene !== initSponza) if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza)
logfps(); logfps();
animate(); animate();
@ -63,7 +63,7 @@ function logfps() {
// Log fps // Log fps
if (stats !== undefined) { if (stats !== undefined) {
var event = new BD.Event.Fps(); var event = new L3D.BD.Event.Fps();
event.fps = stats.getFps(); event.fps = stats.getFps();
event.send(); event.send();
@ -90,10 +90,10 @@ function init() {
renderer.setClearColor(0x87ceeb); renderer.setClearColor(0x87ceeb);
// Initialize pointer camera // 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 // Initialize previewer
previewer = new Previewer(renderer, scene); previewer = new L3D.Previewer(renderer, scene);
previewer.domElement.style.position ="absolute"; previewer.domElement.style.position ="absolute";
previewer.domElement.style.cssFloat = 'top-left'; previewer.domElement.style.cssFloat = 'top-left';
previewer.domElement.width = container_size.width(); previewer.domElement.width = container_size.width();
@ -106,12 +106,12 @@ function init() {
stats.domElement.style.cssFloat = "top-left"; stats.domElement.style.cssFloat = "top-left";
// Initialize pointer for pointer lock // Initialize pointer for pointer lock
var pointer = new MousePointer(camera1); var pointer = new L3D.MousePointer(camera1);
pointer.domElement.width = container_size.width(); pointer.domElement.width = container_size.width();
pointer.domElement.height = container_size.height(); 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.width = container_size.width();
startCanvas.domElement.height = container_size.height(); startCanvas.domElement.height = container_size.height();
@ -126,11 +126,11 @@ function init() {
startCanvas.render(); startCanvas.render();
cameras = initMainScene(camera1, scene, coins); cameras = initMainScene(camera1, scene, coins);
// cameras = initPeach(camera1, scene, coins); // cameras = L3D.initPeach(camera1, scene, coins);
// cameras = initBobomb(camera1, scene, coins); // cameras = L3D.initBobomb(camera1, scene, coins);
// cameras = initWhomp(camera1, scene, , coins); // cameras = L3D.initWhomp(camera1, scene, , coins);
// cameras = initMountain(camera1, scene, coins); // cameras = L3D.initMountain(camera1, scene, coins);
// cameras = initSponza(camera1, scene, coins); // cameras = L3D.initSponza(camera1, scene, coins);
// Add listeners // Add listeners
initListeners(); initListeners();
@ -168,7 +168,7 @@ function initListeners() {
buttonManager = new ButtonManager(cameras, previewer); buttonManager = new ButtonManager(cameras, previewer);
// Camera selecter for hover and clicking recommendations // 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() { function render() {
@ -177,7 +177,7 @@ function render() {
// 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 Recommendation) {
transform(camera); transform(camera);
camera.traverse(function(elt) { camera.traverse(function(elt) {
@ -211,7 +211,7 @@ function render() {
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 Recommendation) hide(camera); });
// Update transparent elements // Update transparent elements
THREEx.Transparency.update(cameras.mainCamera()); THREEx.Transparency.update(cameras.mainCamera());

View File

@ -71,7 +71,7 @@ function init() {
container.appendChild(renderer.domElement); container.appendChild(renderer.domElement);
// Initialize pointer camera // 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); cameras = initMainScene(camera1, scene, coins);
camera1.cameras = cameras; camera1.cameras = cameras;

View File

@ -41,7 +41,7 @@ var TutoCamera = function() {
this.raycaster = new THREE.Raycaster(); this.raycaster = new THREE.Raycaster();
// Create history object // Create history object
this.history = new History(); this.history = new L3D.History();
// Set events from the document // Set events from the document
var self = this; var self = this;
@ -75,8 +75,6 @@ var TutoCamera = function() {
this.collisions = true; this.collisions = true;
this.resetElements = resetBobombElements();
// Create tutorial // Create tutorial
this.tutorial = new TutorialSteps(this, scene, coins, this.onWindowResize, container_size); 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) { TutoCamera.prototype.linearMotion = function(time) {
var position_direction = Tools.diff(this.new_position, this.position); var position_direction = L3D.Tools.diff(this.new_position, this.position);
var target_direction = Tools.diff(this.new_target, this.target); var target_direction = L3D.Tools.diff(this.new_target, this.target);
this.position.add(Tools.mul(position_direction, 0.05 * time / 20)); this.position.add(L3D.Tools.mul(position_direction, 0.05 * time / 20));
this.target.add(Tools.mul(target_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 && if (L3D.Tools.norm2(L3D.Tools.diff(this.position, this.new_position)) < 0.01 &&
Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.01) { L3D.Tools.norm2(L3D.Tools.diff(this.target, this.new_target)) < 0.01) {
this.moving = false; this.moving = false;
this.anglesFromVectors(); this.anglesFromVectors();
} }
@ -188,7 +186,7 @@ TutoCamera.prototype.hermiteMotion = function(time) {
this.position.y = e.y; this.position.y = e.y;
this.position.z = e.z; 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; this.t += 0.01 * time / 20;
@ -238,18 +236,18 @@ TutoCamera.prototype.normalMotion = function(time) {
var direction = new THREE.Vector3(); var direction = new THREE.Vector3();
if (this.motion.boost) speed *= 10; if (this.motion.boost) speed *= 10;
if (this.motion.moveForward) {direction.add(Tools.mul(forward, speed)); this.changed = true;} if (this.motion.moveForward) {direction.add(L3D.Tools.mul(forward, speed)); this.changed = true;}
if (this.motion.moveBackward) {direction.sub(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(Tools.mul(left, speed)); this.changed = true;} if (this.motion.moveLeft) {direction.add(L3D.Tools.mul(left, speed)); this.changed = true;}
if (this.motion.moveRight) {direction.sub(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); var collide = this.isColliding(direction);
if (this.collisions && collide) { if (this.collisions && collide) {
var face = collide.face; var face = collide.face;
var vertices = collide.object.geometry.vertices; 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); normal.multiplyScalar(-1);
} }
@ -272,7 +270,7 @@ TutoCamera.prototype.reset = function() {
this.resetPosition(); this.resetPosition();
this.moving = false; this.moving = false;
this.movingHermite = false; this.movingHermite = false;
(new BD.Event.ResetClicked()).send(); (new L3D.BD.Event.ResetClicked()).send();
this.previousTheta = this.theta; this.previousTheta = this.theta;
this.previousPhi = this.phi; this.previousPhi = this.phi;
@ -296,7 +294,7 @@ TutoCamera.prototype.vectorsFromAngles = function() {
}; };
TutoCamera.prototype.anglesFromVectors = function() { TutoCamera.prototype.anglesFromVectors = function() {
var forward = Tools.diff(this.target, this.position); var forward = L3D.Tools.diff(this.target, this.position);
forward.normalize(); forward.normalize();
this.phi = Math.asin(forward.y); this.phi = Math.asin(forward.y);
@ -315,8 +313,8 @@ TutoCamera.prototype.move = function(otherCamera, toSave) {
this.new_position = otherCamera.position.clone(); this.new_position = otherCamera.position.clone();
var t = [0,1]; var t = [0,1];
var f = [this.position.clone(), this.new_position]; var f = [this.position.clone(), this.new_position];
var fp = [Tools.diff(this.target, this.position), Tools.diff(this.new_target, this.new_position)]; var fp = [L3D.Tools.diff(this.target, this.position), L3D.Tools.diff(this.new_target, this.new_position)];
this.hermite = new Hermite.Polynom(t,f,fp); this.hermite = new L3D.Hermite.Polynom(t,f,fp);
this.t = 0; this.t = 0;
if (toSave) { if (toSave) {
@ -339,15 +337,15 @@ TutoCamera.prototype.moveHermite = function(otherCamera, toSave) {
this.movingHermite = true; this.movingHermite = true;
this.t = 0; this.t = 0;
this.hermitePosition = new Hermite.special.Polynom( this.hermitePosition = new L3D.Hermite.special.Polynom(
this.position.clone(), this.position.clone(),
otherCamera.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( this.hermiteAngles = new L3D.Hermite.special.Polynom(
Tools.diff(this.target, this.position), L3D.Tools.diff(this.target, this.position),
Tools.diff(otherCamera.target, otherCamera.position), L3D.Tools.diff(otherCamera.target, otherCamera.position),
new THREE.Vector3() new THREE.Vector3()
); );
@ -365,7 +363,7 @@ TutoCamera.prototype.isColliding = function(direction) {
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 < L3D.Tools.norm(direction) + this.speed * 300 &&
intersects[i].object.raycastable) { intersects[i].object.raycastable) {
return intersects[i]; return intersects[i];
} }
@ -430,7 +428,7 @@ TutoCamera.prototype.onKeyEvent = function(event, toSet) {
if (motionJsonCopy != JSON.stringify(this.motion)) { if (motionJsonCopy != JSON.stringify(this.motion)) {
// Log any change // Log any change
var e = new BD.Event.KeyboardEvent(); var e = new L3D.BD.Event.KeyboardEvent();
e.camera = this; e.camera = this;
e.send(); e.send();
} }
@ -498,7 +496,7 @@ TutoCamera.prototype.onMouseUp = function(event) {
// Send log to DB // Send log to DB
if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) { 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.camera = this;
e.send(); e.send();
} }
@ -521,7 +519,7 @@ TutoCamera.prototype.save = function() {
TutoCamera.prototype.undo = function() { TutoCamera.prototype.undo = function() {
var move = this.history.undo(); var move = this.history.undo();
if (move !== undefined) { if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked(); var event = new L3D.BD.Event.PreviousNextClicked();
event.previous = true; event.previous = true;
event.camera = move; event.camera = move;
event.send(); event.send();
@ -533,7 +531,7 @@ TutoCamera.prototype.undo = function() {
TutoCamera.prototype.redo = function() { TutoCamera.prototype.redo = function() {
var move = this.history.redo(); var move = this.history.redo();
if (move !== undefined) { if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked(); var event = new L3D.BD.Event.PreviousNextClicked();
event.previous = false; event.previous = false;
event.camera = move; event.camera = move;
event.send(); event.send();

View File

@ -148,7 +148,7 @@ TutorialSteps.prototype.nextStep = function() {
}); });
break; break;
case 14: 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); this.cameras.push(cam);
cam.addToScene(this.scene); cam.addToScene(this.scene);
this.camera.move({ this.camera.move({
@ -157,7 +157,7 @@ TutorialSteps.prototype.nextStep = function() {
}); });
break; break;
case 16: 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++) { for (var i = 0; i < cams.length; i == 1 ? i+=2 : i++) {
this.cameras.push(cams[i]); this.cameras.push(cams[i]);
cams[i].addToScene(this.scene); cams[i].addToScene(this.scene);

View File

@ -36,7 +36,7 @@ function init() {
scene = new THREE.Scene(); scene = new THREE.Scene();
// Disable log for this time // Disable log for this time
BD.disable(); L3D.BD.disable();
// Collidable objects to prevent camera from traversing objects // Collidable objects to prevent camera from traversing objects
var collidableObjects = []; var collidableObjects = [];
@ -52,7 +52,7 @@ function init() {
renderer.setClearColor(0x87ceeb); renderer.setClearColor(0x87ceeb);
// Initialize previewer // Initialize previewer
previewer = new Previewer(renderer, scene); previewer = new L3D.Previewer(renderer, scene);
previewer.domElement.style.position ="absolute"; previewer.domElement.style.position ="absolute";
previewer.domElement.style.cssFloat = 'top-left'; previewer.domElement.style.cssFloat = 'top-left';
previewer.domElement.width = container_size.width(); 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); 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 // Initialize pointer for pointer lock
var pointer = new MousePointer(camera1); var pointer = new L3D.MousePointer(camera1);
pointer.domElement.width = container_size.width(); pointer.domElement.width = container_size.width();
pointer.domElement.height = container_size.height(); 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.width = container_size.width();
startCanvas.domElement.height = container_size.height(); startCanvas.domElement.height = container_size.height();
startCanvas.render(); startCanvas.render();
@ -88,11 +88,11 @@ function init() {
// Initialize pointer camera // Initialize pointer camera
tutorial = camera1.tutorial; tutorial = camera1.tutorial;
cameras = new CameraContainer(camera1, []); cameras = new L3D.CameraContainer(camera1, []);
tutorial.setCameras(cameras); tutorial.setCameras(cameras);
// Load peach scene // Load peach scene
initPeach(camera1, scene); L3D.initPeach(camera1, scene);
initListeners(); initListeners();
@ -124,7 +124,7 @@ function initListeners() {
buttonManager = new ButtonManager(cameras, previewer); buttonManager = new ButtonManager(cameras, previewer);
// Camera selecter for hover and clicking recommendations // 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) // 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 Recommendation) {
transform(camera); transform(camera);
camera.traverse(function(elt) { camera.traverse(function(elt) {
@ -168,7 +168,7 @@ function render() {
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 Recommendation) hide(camera); });
// Render preview // Render preview
previewer.render(cameraSelecter.prev, container_size.width(), container_size.height()); previewer.render(cameraSelecter.prev, container_size.width(), container_size.height());

View File

@ -38,18 +38,18 @@ function init() {
scene.add(ambient_light); scene.add(ambient_light);
// on initialise la camera que lon place ensuite sur la scène // on initialise la camera que lon 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); scene.add(camera);
window.addEventListener('resize', onWindowResize, false); window.addEventListener('resize', onWindowResize, false);
// Load the scene // Load the scene
// loader = new THREE.OBJLoader(); // 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(); sphereLoader.load();
sphere = sphereLoader.obj; sphere = sphereLoader.obj;
plane = new Plane(1000,1000); plane = new L3D.Plane(1000,1000);
plane.translate(0,0,-100); plane.translate(0,0,-100);
plane.addToScene(scene); plane.addToScene(scene);

View File

@ -1,31 +1,30 @@
// class camera extends THREE.PerspectiveCamera L3D.Camera = function() {
var Camera = function() {
THREE.PerspectiveCamera.apply(this, arguments); THREE.PerspectiveCamera.apply(this, arguments);
this.theta = 0; this.theta = 0;
this.position.x = Camera.DISTANCE_X; this.position.x = L3D.Camera.DISTANCE_X;
this.position.z = Camera.DISTANCE_Z; this.position.z = L3D.Camera.DISTANCE_Z;
this.up = new THREE.Vector3(0,0,1); this.up = new THREE.Vector3(0,0,1);
this.target = new THREE.Vector3(); this.target = new THREE.Vector3();
}; };
Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype); L3D.Camera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
// Update function // Update function
Camera.prototype.update = function(time) { L3D.Camera.prototype.update = function(time) {
if (time === undefined) { if (time === undefined) {
time = 20; time = 20;
} }
this.theta += 0.01 * time / 20; this.theta += 0.01 * time / 20;
this.position.x = Camera.DISTANCE_X*Math.cos(this.theta); this.position.x = L3D.Camera.DISTANCE_X*Math.cos(this.theta);
this.position.y = Camera.DISTANCE_X*Math.sin(this.theta); this.position.y = L3D.Camera.DISTANCE_X*Math.sin(this.theta);
}; };
// Look function // Look function
Camera.prototype.look = function() { L3D.Camera.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
// Static members // Static members
Camera.DISTANCE_X = 1000; L3D.Camera.DISTANCE_X = 1000;
Camera.DISTANCE_Z = 300; L3D.Camera.DISTANCE_Z = 300;

View File

@ -1,4 +1,4 @@
var CameraContainer = function (pointerCamera, cameras) { L3D.CameraContainer = function (pointerCamera, cameras) {
if (cameras !== undefined) { if (cameras !== undefined) {
this.cameras = cameras; this.cameras = cameras;
} else { } else {
@ -10,7 +10,7 @@ var CameraContainer = function (pointerCamera, cameras) {
} }
}; };
CameraContainer.prototype.mainCamera = function(id) { L3D.CameraContainer.prototype.mainCamera = function(id) {
if (id === undefined) { if (id === undefined) {
return this.pointerCamera; return this.pointerCamera;
} }
@ -22,35 +22,35 @@ CameraContainer.prototype.mainCamera = function(id) {
this.current_camera = id; this.current_camera = id;
}; };
CameraContainer.prototype.forEach = function(callback) { L3D.CameraContainer.prototype.forEach = function(callback) {
callback(this.pointerCamera); callback(this.pointerCamera);
this.cameras.forEach(callback); this.cameras.forEach(callback);
}; };
CameraContainer.prototype.look = function() { L3D.CameraContainer.prototype.look = function() {
this.mainCamera().look(); this.mainCamera().look();
}; };
CameraContainer.prototype.updateMainCamera = function(time) { L3D.CameraContainer.prototype.updateMainCamera = function(time) {
this.pointerCamera.update(time); this.pointerCamera.update(time);
}; };
CameraContainer.prototype.update = function(position) { L3D.CameraContainer.prototype.update = function(position) {
this.cameras.map(function (elt) { elt.update(position); }); this.cameras.map(function (elt) { elt.update(position); });
}; };
CameraContainer.prototype.push = function(camera) { L3D.CameraContainer.prototype.push = function(camera) {
this.pointerCamera = camera; this.pointerCamera = camera;
this.push = function(camera) { this.push = function(camera) {
this.cameras.push(camera); this.cameras.push(camera);
}; };
}; };
CameraContainer.prototype.get = function(i) { L3D.CameraContainer.prototype.get = function(i) {
return this.cameras[i]; return this.cameras[i];
}; };
CameraContainer.prototype.getByObject = function(object) { L3D.CameraContainer.prototype.getByObject = function(object) {
for (var i in this.cameras) { for (var i in this.cameras) {
if (this.cameras[i].containsObject(object)) { if (this.cameras[i].containsObject(object)) {
return this.get(i); 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); var i = this.getById(id);
if (i !== -1) if (i !== -1)
this.current_camera = i; this.current_camera = i;
}; };
CameraContainer.prototype.nextCamera = function() { L3D.CameraContainer.prototype.nextCamera = function() {
if (this.cameras.length !== 0) { if (this.cameras.length !== 0) {
this.current_camera++; this.current_camera++;
this.current_camera%=this.cameras.length; this.current_camera%=this.cameras.length;
} }
}; };
CameraContainer.prototype.map = function(callback) { L3D.CameraContainer.prototype.map = function(callback) {
this.cameras.map(callback); this.cameras.map(callback);
}; };

View File

@ -3,7 +3,7 @@
* @constructor * @constructor
* @augments THREE.PerspectiveCamera * @augments THREE.PerspectiveCamera
*/ */
var PointerCamera = function() { L3D.PointerCamera = function() {
THREE.PerspectiveCamera.apply(this, arguments); THREE.PerspectiveCamera.apply(this, arguments);
/** /**
@ -115,9 +115,9 @@ var PointerCamera = function() {
/** /**
* History of the moves of the camera * 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 * 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 * The camera we will move to when we'll reset the camera
* @param {Object} * @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); L3D.PointerCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
PointerCamera.prototype.constructor = PointerCamera; L3D.PointerCamera.prototype.constructor = L3D.PointerCamera;
/** /**
* Locks the pointer inside the canvas, and displays a gun sight at the middle of the renderer * 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 * This method works only if the browser supports requestPointerLock
*/ */
PointerCamera.prototype.lockPointer = function() { L3D.PointerCamera.prototype.lockPointer = function() {
if (this.shouldLock) { if (this.shouldLock) {
this.renderer.domElement.requestPointerLock = this.renderer.domElement.requestPointerLock =
@ -207,7 +207,7 @@ PointerCamera.prototype.lockPointer = function() {
* Check that the pointer is locked or not, and updated locked attribute * Check that the pointer is locked or not, and updated locked attribute
* @returns true if the pointer is locked, false otherwise * @returns true if the pointer is locked, false otherwise
*/ */
PointerCamera.prototype.isLocked = function() { L3D.PointerCamera.prototype.isLocked = function() {
var toto = var toto =
document.pointerLockElement === this.renderer.domElement || document.pointerLockElement === this.renderer.domElement ||
document.mozPointerLockElement === 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 * Update the camera when the pointer lock changes state
*/ */
PointerCamera.prototype.onPointerLockChange = function() { L3D.PointerCamera.prototype.onPointerLockChange = function() {
if (this.isLocked()) { if (this.isLocked()) {
@ -259,7 +259,7 @@ PointerCamera.prototype.onPointerLockChange = function() {
* Update the position of the camera * Update the position of the camera
* @param {Number} time number of milliseconds between the previous and the next frame * @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) { if (this.moving) {
this.linearMotion(time); this.linearMotion(time);
} else if (this.movingHermite) { } else if (this.movingHermite) {
@ -273,15 +273,15 @@ PointerCamera.prototype.update = function(time) {
* Update the camera according to its linear motion * Update the camera according to its linear motion
* @param {Number} time number of milliseconds between the previous and the next frame * @param {Number} time number of milliseconds between the previous and the next frame
*/ */
PointerCamera.prototype.linearMotion = function(time) { L3D.PointerCamera.prototype.linearMotion = function(time) {
var position_direction = Tools.diff(this.new_position, this.position); var position_direction = L3D.Tools.diff(this.new_position, this.position);
var target_direction = Tools.diff(this.new_target, this.target); var target_direction = L3D.Tools.diff(this.new_target, this.target);
this.position.add(Tools.mul(position_direction, 0.05 * time / 20)); this.position.add(L3D.Tools.mul(position_direction, 0.05 * time / 20));
this.target.add(Tools.mul(target_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 && if (L3D.Tools.norm2(L3D.Tools.diff(this.position, this.new_position)) < 0.01 &&
Tools.norm2(Tools.diff(this.target, this.new_target)) < 0.01) { L3D.Tools.norm2(L3D.Tools.diff(this.target, this.new_target)) < 0.01) {
this.moving = false; this.moving = false;
this.anglesFromVectors(); this.anglesFromVectors();
} }
@ -291,13 +291,13 @@ PointerCamera.prototype.linearMotion = function(time) {
* Update the camera according to its hermite motion * Update the camera according to its hermite motion
* @param {Number} time number of milliseconds between the previous and the next frame * @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); var e = this.hermitePosition.eval(this.t);
this.position.x = e.x; this.position.x = e.x;
this.position.y = e.y; this.position.y = e.y;
this.position.z = e.z; 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; this.t += 0.01 * time / 20;
@ -311,7 +311,7 @@ PointerCamera.prototype.hermiteMotion = function(time) {
* Update the camera according to the user's input * Update the camera according to the user's input
* @param {Number} time number of milliseconds between the previous and the next frame * @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 // Update angles
if (this.motion.increasePhi) {this.phi += this.sensitivity * time / 20; this.changed = true; } 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; self.shouldLogCameraAngles = true;
}, 100); }, 100);
var event = new BD.Event.KeyboardEvent(); var event = new L3D.BD.Event.KeyboardEvent();
event.camera = this; event.camera = this;
} }
@ -367,10 +367,10 @@ PointerCamera.prototype.normalMotion = function(time) {
var direction = new THREE.Vector3(); var direction = new THREE.Vector3();
if (this.motion.boost) speed *= 10; if (this.motion.boost) speed *= 10;
if (this.motion.moveForward) {direction.add(Tools.mul(forward, speed)); this.changed = true;} if (this.motion.moveForward) {direction.add(L3D.Tools.mul(forward, speed)); this.changed = true;}
if (this.motion.moveBackward) {direction.sub(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(Tools.mul(left, speed)); this.changed = true;} if (this.motion.moveLeft) {direction.add(L3D.Tools.mul(left, speed)); this.changed = true;}
if (this.motion.moveRight) {direction.sub(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)) { if (!this.collisions || !this.isColliding(direction)) {
this.position.add(direction); this.position.add(direction);
@ -384,17 +384,17 @@ PointerCamera.prototype.normalMotion = function(time) {
/** /**
* Reset the camera to its resetElements, and finishes any motion * Reset the camera to its resetElements, and finishes any motion
*/ */
PointerCamera.prototype.reset = function() { L3D.PointerCamera.prototype.reset = function() {
this.resetPosition(); this.resetPosition();
this.moving = false; this.moving = false;
this.movingHermite = false; this.movingHermite = false;
(new BD.Event.ResetClicked()).send(); (new L3D.BD.Event.ResetClicked()).send();
}; };
/** /**
* Reset the position of th camera * Reset the position of th camera
*/ */
PointerCamera.prototype.resetPosition = function() { L3D.PointerCamera.prototype.resetPosition = function() {
this.position.copy(this.resetElements.position); this.position.copy(this.resetElements.position);
this.target.copy(this.resetElements.target); this.target.copy(this.resetElements.target);
this.anglesFromVectors(); this.anglesFromVectors();
@ -403,7 +403,7 @@ PointerCamera.prototype.resetPosition = function() {
/** /**
* Computes the vectors (forward, left, ...) according to theta and phi * Computes the vectors (forward, left, ...) according to theta and phi
*/ */
PointerCamera.prototype.vectorsFromAngles = function() { L3D.PointerCamera.prototype.vectorsFromAngles = function() {
// Update direction // Update direction
this.forward.y = Math.sin(this.phi); 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, ...) * Computes theta and phi according to the vectors (forward, left, ...)
*/ */
PointerCamera.prototype.anglesFromVectors = function() { L3D.PointerCamera.prototype.anglesFromVectors = function() {
var forward = Tools.diff(this.target, this.position); var forward = L3D.Tools.diff(this.target, this.position);
forward.normalize(); forward.normalize();
this.phi = Math.asin(forward.y); this.phi = Math.asin(forward.y);
@ -433,7 +433,7 @@ PointerCamera.prototype.anglesFromVectors = function() {
* @param {Camera} camera Camera to move to * @param {Camera} camera Camera to move to
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera * @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) if (toSave === undefined)
toSave = true; toSave = true;
@ -442,8 +442,8 @@ PointerCamera.prototype.move = function(otherCamera, toSave) {
this.new_position = otherCamera.position.clone(); this.new_position = otherCamera.position.clone();
var t = [0,1]; var t = [0,1];
var f = [this.position.clone(), this.new_position]; var f = [this.position.clone(), this.new_position];
var fp = [Tools.diff(this.target, this.position), Tools.diff(this.new_target, this.new_position)]; var fp = [L3D.Tools.diff(this.target, this.position), L3D.Tools.diff(this.new_target, this.new_position)];
this.hermite = new Hermite.Polynom(t,f,fp); this.hermite = new L3D.Hermite.Polynom(t,f,fp);
this.t = 0; this.t = 0;
if (toSave) { if (toSave) {
@ -460,22 +460,22 @@ PointerCamera.prototype.move = function(otherCamera, toSave) {
* @param {Camera} camera Camera to move to * @param {Camera} camera Camera to move to
* @param {Boolean} [toSave=true] true if you want to save the current state of the camera * @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) if (toSave === undefined)
toSave = true; toSave = true;
this.movingHermite = true; this.movingHermite = true;
this.t = 0; this.t = 0;
this.hermitePosition = new Hermite.special.Polynom( this.hermitePosition = new L3D.Hermite.special.Polynom(
this.position.clone(), this.position.clone(),
otherCamera.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( this.hermiteAngles = new L3D.Hermite.special.Polynom(
Tools.diff(this.target, this.position), L3D.Tools.diff(this.target, this.position),
Tools.diff(otherCamera.target, otherCamera.position), L3D.Tools.diff(otherCamera.target, otherCamera.position),
new THREE.Vector3() new THREE.Vector3()
); );
@ -493,12 +493,12 @@ PointerCamera.prototype.moveHermite = function(otherCamera, toSave) {
* @param {THREE.Vector3} direction the direction of the camera * @param {THREE.Vector3} direction the direction of the camera
* @returns {Boolean} true if there is a collision, false otherwise * @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()); 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 < L3D.Tools.norm(direction) + this.speed * 300 &&
intersects[i].object.raycastable) { intersects[i].object.raycastable) {
return true; return true;
} }
@ -510,14 +510,14 @@ PointerCamera.prototype.isColliding = function(direction) {
/** /**
* Look method. Equivalent to gluLookAt for the current camera * Look method. Equivalent to gluLookAt for the current camera
*/ */
PointerCamera.prototype.look = function() { L3D.PointerCamera.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
/** /**
* Adds the camera to the scene * Adds the camera to the scene
*/ */
PointerCamera.prototype.addToScene = function(scene) { L3D.PointerCamera.prototype.addToScene = function(scene) {
scene.add(this); scene.add(this);
}; };
@ -526,7 +526,7 @@ PointerCamera.prototype.addToScene = function(scene) {
* @param {event} event the event that happened * @param {event} event the event that happened
* @param {Booelean} toSet true if the key was pressed, false if released * @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 // Create copy of state
var motionJsonCopy = JSON.stringify(this.motion); var motionJsonCopy = JSON.stringify(this.motion);
@ -553,7 +553,7 @@ PointerCamera.prototype.onKeyEvent = function(event, toSet) {
} }
if (motionJsonCopy != JSON.stringify(this.motion)) { if (motionJsonCopy != JSON.stringify(this.motion)) {
// Log any change // Log any change
var e = new BD.Event.KeyboardEvent(); var e = new L3D.BD.Event.KeyboardEvent();
e.camera = this; e.camera = this;
e.send(); e.send();
} }
@ -563,7 +563,7 @@ PointerCamera.prototype.onKeyEvent = function(event, toSet) {
* Manages the key pressed events * Manages the key pressed events
* @param {event} event the event to manage * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onKeyDown = function(event) { L3D.PointerCamera.prototype.onKeyDown = function(event) {
this.onKeyEvent(event, true); this.onKeyEvent(event, true);
}; };
@ -571,7 +571,7 @@ PointerCamera.prototype.onKeyDown = function(event) {
* Manages the key released events * Manages the key released events
* @param {event} event the event to manage * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onKeyUp = function(event) { L3D.PointerCamera.prototype.onKeyUp = function(event) {
this.onKeyEvent(event, false); 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 * 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 * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onMouseDown = function(event) { L3D.PointerCamera.prototype.onMouseDown = function(event) {
if (!this.shouldLock) { 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 * 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 * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onMouseMove = function(event) { L3D.PointerCamera.prototype.onMouseMove = function(event) {
if (!this.shouldLock && this.dragging) { if (!this.shouldLock && this.dragging) {
var mouse = {x: this.mouse.x, y: this.mouse.y}; 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 * Manages the mouse move envent in case of pointer lock
* @param {event} event the event to manage * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onMouseMovePointer = function(e) { L3D.PointerCamera.prototype.onMouseMovePointer = function(e) {
if (this.isLocked()) { if (this.isLocked()) {
@ -637,12 +637,12 @@ PointerCamera.prototype.onMouseMovePointer = function(e) {
* Manages the mouse up event. Stops the dragging * Manages the mouse up event. Stops the dragging
* @param {event} event the event to manage * @param {event} event the event to manage
*/ */
PointerCamera.prototype.onMouseUp = function(event) { L3D.PointerCamera.prototype.onMouseUp = function(event) {
this.onMouseMove(event); this.onMouseMove(event);
// Send log to DB // Send log to DB
if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) { 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.camera = this;
e.send(); e.send();
} }
@ -653,7 +653,7 @@ PointerCamera.prototype.onMouseUp = function(event) {
/** /**
* Logs the camera to the terminal (pratical to create recommended views) * 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' + 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)'); "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 * Save the current state of the camera in the history
*/ */
PointerCamera.prototype.save = function() { L3D.PointerCamera.prototype.save = function() {
var backup = {}; var backup = {};
backup.position = this.position.clone(); backup.position = this.position.clone();
backup.target = this.target.clone(); backup.target = this.target.clone();
@ -671,10 +671,10 @@ PointerCamera.prototype.save = function() {
/** /**
* Undo last motion according to the history * Undo last motion according to the history
*/ */
PointerCamera.prototype.undo = function() { L3D.PointerCamera.prototype.undo = function() {
var move = this.history.undo(); var move = this.history.undo();
if (move !== undefined) { if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked(); var event = new L3D.BD.Event.PreviousNextClicked();
event.previous = true; event.previous = true;
event.camera = move; event.camera = move;
event.send(); event.send();
@ -686,10 +686,10 @@ PointerCamera.prototype.undo = function() {
/** /**
* Redo last motion according to the history * Redo last motion according to the history
*/ */
PointerCamera.prototype.redo = function() { L3D.PointerCamera.prototype.redo = function() {
var move = this.history.redo(); var move = this.history.redo();
if (move !== undefined) { if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked(); var event = new L3D.BD.Event.PreviousNextClicked();
event.previous = false; event.previous = false;
event.camera = move; event.camera = move;
event.send(); event.send();
@ -702,7 +702,7 @@ PointerCamera.prototype.redo = function() {
* Checks if there is a undo possibility in the history * Checks if there is a undo possibility in the history
* @returns {Boolean} true if undo is possible, false otherwise * @returns {Boolean} true if undo is possible, false otherwise
*/ */
PointerCamera.prototype.undoable = function() { L3D.PointerCamera.prototype.undoable = function() {
return this.history.undoable(); return this.history.undoable();
}; };
@ -710,11 +710,11 @@ PointerCamera.prototype.undoable = function() {
* Checks if there is a redo possibility in the history * Checks if there is a redo possibility in the history
* @returns {Boolean} true if redo is possible, false otherwise * @returns {Boolean} true if redo is possible, false otherwise
*/ */
PointerCamera.prototype.redoable = function() { L3D.PointerCamera.prototype.redoable = function() {
return this.history.redoable(); return this.history.redoable();
}; };
PointerCamera.prototype.toList = function() { L3D.PointerCamera.prototype.toList = function() {
this.updateMatrix(); this.updateMatrix();
this.updateMatrixWorld(); this.updateMatrixWorld();

View File

@ -1,5 +1,5 @@
// class camera extends THREE.PerspectiveCamera // class camera extends THREE.PerspectiveCamera
var ReplayCamera = function() { L3D.ReplayCamera = function() {
THREE.PerspectiveCamera.apply(this, arguments); THREE.PerspectiveCamera.apply(this, arguments);
this.coins = arguments[4]; this.coins = arguments[4];
@ -31,18 +31,16 @@ var ReplayCamera = function() {
this.theta = Math.PI; this.theta = Math.PI;
this.phi = Math.PI; this.phi = Math.PI;
this.resetElements = resetBobombElements();
}; };
ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); L3D.ReplayCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype);
ReplayCamera.prototype.constructor = ReplayCamera; L3D.ReplayCamera.prototype.constructor = L3D.ReplayCamera;
ReplayCamera.prototype.look = function() { L3D.ReplayCamera.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
// Update function // Update function
ReplayCamera.prototype.update = function(time) { L3D.ReplayCamera.prototype.update = function(time) {
if (this.started) { if (this.started) {
if (this.event.type == 'camera') { if (this.event.type == 'camera') {
this.cameraMotion(time); this.cameraMotion(time);
@ -59,8 +57,8 @@ ReplayCamera.prototype.update = function(time) {
} }
}; };
ReplayCamera.prototype.linearMotion = function(time) { L3D.ReplayCamera.prototype.linearMotion = 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.x = tmp.x;
this.position.y = tmp.y; this.position.y = tmp.y;
this.position.z = tmp.z; 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.x = tmp.x;
this.position.y = tmp.y; this.position.y = tmp.y;
this.position.z = tmp.z; 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); 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) { 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); var e = this.hermitePosition.eval(this.t);
this.position.x = e.x; this.position.x = e.x;
this.position.y = e.y; this.position.y = e.y;
this.position.z = e.z; 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; 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++; this.counter++;
// Finished // Finished
@ -137,19 +135,19 @@ ReplayCamera.prototype.nextEvent = function() {
} }
}; };
ReplayCamera.prototype.reset = function() { L3D.ReplayCamera.prototype.reset = function() {
this.resetPosition(); this.resetPosition();
this.moving = false; this.moving = false;
this.movingHermite = false; this.movingHermite = false;
}; };
ReplayCamera.prototype.resetPosition = function() { L3D.ReplayCamera.prototype.resetPosition = function() {
this.position.copy(this.resetElements.position); this.position.copy(this.resetElements.position);
this.target.copy(this.resetElements.target); this.target.copy(this.resetElements.target);
this.anglesFromVectors(); this.anglesFromVectors();
}; };
ReplayCamera.prototype.vectorsFromAngles = function() { L3D.ReplayCamera.prototype.vectorsFromAngles = function() {
// Update direction // Update direction
this.forward.y = Math.sin(this.phi); 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 // 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(); forward.normalize();
this.phi = Math.asin(forward.y); this.phi = Math.asin(forward.y);
@ -172,7 +170,7 @@ ReplayCamera.prototype.anglesFromVectors = function() {
this.theta = Math.atan2(forward.x, forward.z); this.theta = Math.atan2(forward.x, forward.z);
}; };
ReplayCamera.prototype.move = function(otherCamera) { L3D.ReplayCamera.prototype.move = function(otherCamera) {
this.moving = true; this.moving = true;
this.old_target = this.target.clone(); this.old_target = this.target.clone();
this.old_position = this.position.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.movingHermite = true;
this.t = 0; this.t = 0;
this.hermitePosition = new Hermite.special.Polynom( this.hermitePosition = new L3D.Hermite.special.Polynom(
this.position.clone(), this.position.clone(),
otherCamera.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( this.hermiteAngles = new L3D.Hermite.special.Polynom(
Tools.diff(this.target, this.position), L3D.Tools.diff(this.target, this.position),
Tools.diff(otherCamera.target, otherCamera.position), L3D.Tools.diff(otherCamera.target, otherCamera.position),
new THREE.Vector3() new THREE.Vector3()
); );
}; };
ReplayCamera.prototype.save = function() {}; L3D.ReplayCamera.prototype.save = function() {};

View File

@ -1,4 +1,4 @@
var MousePointer = function(camera) { L3D.MousePointer = function(camera) {
this.domElement = document.createElement('canvas'); this.domElement = document.createElement('canvas');
this.domElement.style.position = 'absolute'; this.domElement.style.position = 'absolute';
@ -7,37 +7,37 @@ var MousePointer = function(camera) {
this.size = 10; this.size = 10;
this.drawn = false; this.drawn = false;
camera.mousePointer = this; camera.mousePointer = this;
this.style = MousePointer.NONE; this.style = L3D.MousePointer.NONE;
}; };
MousePointer.NONE = 0; L3D.MousePointer.NONE = 0;
MousePointer.BLACK = 1; L3D.MousePointer.BLACK = 1;
MousePointer.RED = 2; L3D.MousePointer.RED = 2;
MousePointer.toColor = function(style) { L3D.MousePointer.toColor = function(style) {
switch (style) { switch (style) {
case MousePointer.NONE: case L3D.MousePointer.NONE:
return null; return null;
case MousePointer.BLACK: case L3D.MousePointer.BLACK:
return '#000000'; return '#000000';
case MousePointer.RED: case L3D.MousePointer.RED:
return '#ff0000'; return '#ff0000';
} }
}; };
MousePointer.prototype.render = function(style) { L3D.MousePointer.prototype.render = function(style) {
if (this.style !== style) { if (this.style !== style) {
if (style === MousePointer.NONE) { if (style === L3D.MousePointer.NONE) {
// Clear canvas // Clear canvas
this.domElement.width = this.domElement.width; this.domElement.width = this.domElement.width;
this.style = MousePointer.NONE; this.style = L3D.MousePointer.NONE;
} else { } else {
@ -64,7 +64,7 @@ MousePointer.prototype.render = function(style) {
this.ctx.stroke(); this.ctx.stroke();
this.ctx.lineWidth = 2; this.ctx.lineWidth = 2;
this.ctx.strokeStyle = MousePointer.toColor(style); this.ctx.strokeStyle = L3D.MousePointer.toColor(style);
this.ctx.stroke(); this.ctx.stroke();
this.style = style; 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);
}; };

View File

@ -2,7 +2,7 @@ Math.clamp = Math.clamp || function(number, min, max) {
return Math.max(Math.min(number, max), min); return Math.max(Math.min(number, max), min);
}; };
var Previewer = function(renderer, scene) { L3D.Previewer = function(renderer, scene) {
this.domElement = document.createElement('canvas'); this.domElement = document.createElement('canvas');
this.ctx = this.domElement.getContext('2d'); this.ctx = this.domElement.getContext('2d');
this.renderer = renderer; this.renderer = renderer;
@ -12,7 +12,7 @@ var Previewer = function(renderer, scene) {
this.drawnBefore = false; 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; var width, height, left, bottom;
if (prev.go) { 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) { if (this.clearNeeded) {
this.domElement.width = this.domElement.width; this.domElement.width = this.domElement.width;
this.clearNeeded = false; this.clearNeeded = false;
} }
}; };
Previewer.prototype.fixedRecommendation = function(bool) { L3D.Previewer.prototype.fixedRecommendation = function(bool) {
this.fixed = bool; this.fixed = bool;
}; };
Previewer.prototype.update = function(arg) { L3D.Previewer.prototype.update = function(arg) {
this.drawnBefore = this.drawn; this.drawnBefore = this.drawn;
this.drawn = arg; this.drawn = arg;
}; };

View File

@ -1,4 +1,4 @@
var StartCanvas = function(camera) { L3D.StartCanvas = function(camera) {
this.domElement = document.createElement('canvas'); this.domElement = document.createElement('canvas');
this.domElement.style.position = 'absolute'; 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) { if (!this.shown) {
@ -30,7 +30,7 @@ StartCanvas.prototype.render = function() {
}; };
StartCanvas.prototype.clear = function() { L3D.StartCanvas.prototype.clear = function() {
if (this.shown) { if (this.shown) {

View File

@ -1,4 +1,4 @@
var _parseList = function(arr) { L3D._parseList = function(arr) {
var ret = {}; var ret = {};
ret.index = arr[1]; ret.index = arr[1];
@ -63,7 +63,7 @@ var _parseList = function(arr) {
return ret; return ret;
}; };
var ProgressiveLoader = function(path, scene, camera, callback) { L3D.ProgressiveLoader = function(path, scene, camera, callback) {
// Init attributes // Init attributes
this.objPath = path.substring(1, path.length); this.objPath = path.substring(1, path.length);
this.texturesPath = path.substring(0, path.lastIndexOf('/')) + '/'; 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; var self = this;
@ -106,7 +106,7 @@ ProgressiveLoader.prototype.load = function() {
}); });
}; };
ProgressiveLoader.prototype.initIOCallbacks = function() { L3D.ProgressiveLoader.prototype.initIOCallbacks = function() {
var self = this; 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); this.socket.emit('request', this.objPath);
}; };

View File

@ -2,7 +2,7 @@
* Parse a list as it is sent by the server and gives a slightly more comprehensible result * Parse a list as it is sent by the server and gives a slightly more comprehensible result
* @private * @private
*/ */
var _parseList2 = function(arr) { L3D._parseList2 = function(arr) {
var ret = {}; var ret = {};
ret.index = arr[1]; ret.index = arr[1];
@ -77,8 +77,9 @@ var _parseList2 = function(arr) {
* order) * order)
* @param {function} callback callback to call on the objects when they're created * @param {function} callback callback to call on the objects when they're created
* @constructor * @constructor
* @memberOf L3D
*/ */
var ProgressiveLoaderGeometry = function(path, scene, camera, callback) { L3D.ProgressiveLoaderGeometry = function(path, scene, camera, callback) {
/** /**
* Path to the .obj file * Path to the .obj file
@ -180,7 +181,7 @@ var ProgressiveLoaderGeometry = function(path, scene, camera, callback) {
/** /**
* Starts the loading of the mesh * Starts the loading of the mesh
*/ */
ProgressiveLoaderGeometry.prototype.load = function() { L3D.ProgressiveLoaderGeometry.prototype.load = function() {
var self = this; 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) * 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) if (this.camera === null)
return null; return null;
@ -208,7 +209,7 @@ ProgressiveLoaderGeometry.prototype.getCamera = function() {
/** /**
* Initializes the socket.io functions so that it can discuss with the server * 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; var self = this;
@ -233,7 +234,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
// console.log("Received elements for the " + (++self.counter) + "th time !"); // console.log("Received elements for the " + (++self.counter) + "th time !");
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var elt = _parseList2(arr[i]); var elt = L3D._parseList2(arr[i]);
// console.log(elts); // console.log(elts);
if (elt.type === 'vertex') { if (elt.type === 'vertex') {
@ -371,7 +372,7 @@ ProgressiveLoaderGeometry.prototype.initIOCallbacks = function() {
/** /**
* Starts the communication with the server * Starts the communication with the server
*/ */
ProgressiveLoaderGeometry.prototype.start = function() { L3D.ProgressiveLoaderGeometry.prototype.start = function() {
this.socket.emit('request', this.objPath); this.socket.emit('request', this.objPath);
}; };

View File

@ -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.times = t;
this.evals = f; this.evals = f;
this.primes = fp; this.primes = fp;
@ -8,15 +8,15 @@ Hermite.Polynom = function(t, f, fp) {
this.baseFunctions = []; this.baseFunctions = [];
for (var i in this.times) { 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 // Let's do something at least a little reusable
this.tools = {}; this.tools = {};
if (f[0] instanceof THREE.Vector3) { if (f[0] instanceof THREE.Vector3) {
this.tools.whatType = 'THREE.Vector3'; this.tools.whatType = 'THREE.Vector3';
this.tools.sum = Tools.sum; this.tools.sum = L3D.Tools.sum;
this.tools.prod = Tools.mul; this.tools.prod = L3D.Tools.mul;
} else { } else {
this.tools.whatType = 'number'; this.tools.whatType = 'number';
this.tools.sum = function(a, b) { return a + b; }; 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; var ret;
if (this.tools.whatType === 'THREE.Vector3') { if (this.tools.whatType === 'THREE.Vector3') {
@ -67,7 +67,7 @@ Hermite.Polynom.prototype.eval = function(t) {
return ret; return ret;
}; };
Hermite.Polynom.prototype.prime = function(t) { L3D.Hermite.Polynom.prototype.prime = function(t) {
var ret; var ret;
if (this.tools.whatType === 'THREE.Vector3') { if (this.tools.whatType === 'THREE.Vector3') {
@ -141,12 +141,12 @@ Hermite.Polynom.prototype.prime = function(t) {
return ret; return ret;
}; };
Hermite.BaseFunction = function(index, times) { L3D.Hermite.BaseFunction = function(index, times) {
this.index = index; this.index = index;
this.times = times; this.times = times;
}; };
Hermite.BaseFunction.prototype.eval = function(t) { L3D.Hermite.BaseFunction.prototype.eval = function(t) {
var ret = 1; var ret = 1;
for (var i in this.times) { for (var i in this.times) {
@ -158,7 +158,7 @@ Hermite.BaseFunction.prototype.eval = function(t) {
return ret * ret; return ret * ret;
}; };
Hermite.BaseFunction.prototype.prime = function(t) { L3D.Hermite.BaseFunction.prototype.prime = function(t) {
var ret = 0; var ret = 0;
for (var i in this.times) { for (var i in this.times) {
@ -170,16 +170,16 @@ Hermite.BaseFunction.prototype.prime = function(t) {
return this.eval(t) * ret; return this.eval(t) * ret;
}; };
Hermite.special = {}; L3D.Hermite.special = {};
// This polynom interpolates with two coords and one derivative // This polynom interpolates with two coords and one derivative
// t = [0,1] // t = [0,1]
Hermite.special.Polynom = function(P0, P1, PP1) { L3D.Hermite.special.Polynom = function(P0, P1, PP1) {
this.tools = {}; this.tools = {};
if (P0 instanceof THREE.Vector3) { if (P0 instanceof THREE.Vector3) {
this.tools.sum = Tools.sum; this.tools.sum = L3D.Tools.sum;
this.tools.mul = Tools.mul; this.tools.mul = L3D.Tools.mul;
this.tools.diff = Tools.diff; this.tools.diff = L3D.Tools.diff;
this.c = P0.clone(); this.c = P0.clone();
} else { } else {
this.tools.sum = function(a,b) { return a+b; }; 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); 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)); 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); return this.tools.sum(this.tools.mul(this.a,2*t), this.b);
}; };

View File

@ -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); 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); 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; 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( return new THREE.Vector3(
v1.y * v2.z - v1.z * v2.y, v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z, 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); 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; 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; return v.x * v.x + v.y * v.y + v.z * v.z;
}; };
Tools.norm = function(v) { L3D.Tools.norm = function(v) {
return Math.sqrt(Tools.norm2(v)); return Math.sqrt(L3D.Tools.norm2(v));
}; };

View File

@ -17,10 +17,10 @@ function main() {
// First tests // First tests
document.write("<ol>"); document.write("<ol>");
var v3 = Tools.sum(v1,v2); var v3 = L3D.Tools.sum(v1,v2);
test(v3.x == v1.x + v2.x && v3.y == v1.y + v2.y && v3.z == v1.z + v2.z); test(v3.x == v1.x + v2.x && v3.y == v1.y + v2.y && v3.z == v1.z + v2.z);
test(Tools.equals(v1, v1Bak)); test(L3D.Tools.equals(v1, v1Bak));
test(Tools.equals(v2, v2Bak)); test(L3D.Tools.equals(v2, v2Bak));
document.write('</ol>'); document.write('</ol>');
// Clear v1, v2 // Clear v1, v2
@ -28,30 +28,30 @@ function main() {
v2 = v2Bak.clone(); v2 = v2Bak.clone();
document.write("<ol>"); document.write("<ol>");
var v4 = Tools.diff(v1,v2); var v4 = L3D.Tools.diff(v1,v2);
test(v4.x == v1.x - v2.x && v4.y == v1.y - v2.y && v4.z == v1.z - v2.z); test(v4.x == v1.x - v2.x && v4.y == v1.y - v2.y && v4.z == v1.z - v2.z);
test(Tools.equals(v1, v1Bak)); test(L3D.Tools.equals(v1, v1Bak));
test(Tools.equals(v2, v2Bak)); test(L3D.Tools.equals(v2, v2Bak));
document.write('</ol>'); document.write('</ol>');
v1 = v1Bak.clone(); v1 = v1Bak.clone();
v2 = v2Bak.clone(); v2 = v2Bak.clone();
document.write("<ol>"); document.write("<ol>");
var v5 = Tools.dot(v1,v2); var v5 = L3D.Tools.dot(v1,v2);
test(v5 == v1.x * v2.x + v1.y * v2.y + v1.z * v2.z); test(v5 == v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
test(Tools.equals(v1, v1Bak)); test(L3D.Tools.equals(v1, v1Bak));
test(Tools.equals(v2, v2Bak)); test(L3D.Tools.equals(v2, v2Bak));
document.write('</ol>'); document.write('</ol>');
v1 = v1Bak.clone(); v1 = v1Bak.clone();
v2 = v2Bak.clone(); v2 = v2Bak.clone();
document.write("<ol>"); document.write("<ol>");
var v6 = Tools.cross(new THREE.Vector3(1,0,0), new THREE.Vector3(0,1,0)); var v6 = L3D.Tools.cross(new THREE.Vector3(1,0,0), new THREE.Vector3(0,1,0));
test(Tools.equals(v6, new THREE.Vector3(0,0,1))); test(L3D.Tools.equals(v6, new THREE.Vector3(0,0,1)));
test(Tools.equals(v1, v1Bak)); test(L3D.Tools.equals(v1, v1Bak));
test(Tools.equals(v2, v2Bak)); test(L3D.Tools.equals(v2, v2Bak));
document.write('</ol>'); document.write('</ol>');
v1 = v1Bak.clone(); v1 = v1Bak.clone();
@ -60,18 +60,18 @@ function main() {
document.write("<ol>"); document.write("<ol>");
for (var lambda = 0; lambda < 5; lambda += 0.5) for (var lambda = 0; lambda < 5; lambda += 0.5)
{ {
var v7 = Tools.mul(v1, lambda); var v7 = L3D.Tools.mul(v1, lambda);
test(Tools.equals(v7, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda))); test(L3D.Tools.equals(v7, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda)));
v1 = v1Bak.clone(); v1 = v1Bak.clone();
v2 = v2Bak.clone(); v2 = v2Bak.clone();
var v8 = Tools.mul(v1, lambda); var v8 = L3D.Tools.mul(v1, lambda);
test(Tools.equals(v8, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda))); test(L3D.Tools.equals(v8, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda)));
v1 = v1Bak.clone(); v1 = v1Bak.clone();
v2 = v2Bak.clone(); v2 = v2Bak.clone();
// Try into v1 // Try into v1
v1 = Tools.mul(v1, lambda); v1 = L3D.Tools.mul(v1, lambda);
test(Tools.equals(v1, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda))); test(L3D.Tools.equals(v1, new THREE.Vector3(v1Bak.x*lambda, v1Bak.y*lambda, v1Bak.z*lambda)));
v1 = v1Bak.clone(); v1 = v1Bak.clone();
v2 = v2Bak.clone(); v2 = v2Bak.clone();

View File

@ -1,7 +1,7 @@
// Initialization // Initialization
// class camera extends THREE.PerspectiveCamera // class camera extends THREE.PerspectiveCamera
var ArrowCamera = function(arg1, arg2, arg3, arg4, position, target) { L3D.BaseRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
THREE.PerspectiveCamera.apply(this, arguments); THREE.PerspectiveCamera.apply(this, arguments);
// Set Position // Set Position
@ -24,7 +24,7 @@ var ArrowCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.center.sub(direction); this.center.sub(direction);
this.target = this.position.clone(); this.target = this.position.clone();
this.target.add(Tools.mul(direction,20)); this.target.add(L3D.Tools.mul(direction,20));
this.arrow = new THREE.Mesh(new THREE.Geometry(), new THREE.MeshLambertMaterial({color: 0x0000ff, side:THREE.BackSide})); this.arrow = new THREE.Mesh(new THREE.Geometry(), new THREE.MeshLambertMaterial({color: 0x0000ff, side:THREE.BackSide}));
@ -38,37 +38,37 @@ var ArrowCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.fullArrow = false; this.fullArrow = false;
}; };
ArrowCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); L3D.BaseRecommendation.prototype = Object.create(THREE.PerspectiveCamera.prototype);
ArrowCamera.prototype.constructor = ArrowCamera; L3D.BaseRecommendation.prototype.constructor = L3D.BaseRecommendation;
ArrowCamera.prototype.check = function() { L3D.BaseRecommendation.prototype.check = function() {
this.object3D.traverse(function(obj) { this.object3D.traverse(function(obj) {
if (obj instanceof THREE.Mesh) if (obj instanceof THREE.Mesh)
obj.material.color.setHex(0x663366); obj.material.color.setHex(0x663366);
}); });
}; };
ArrowCamera.prototype.initExtremity = function() { L3D.BaseRecommendation.prototype.initExtremity = function() {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
var direction = this.target.clone(); var direction = this.target.clone();
direction.sub(this.position); direction.sub(this.position);
direction.normalize(); direction.normalize();
var left = Tools.cross(direction, this.up); var left = L3D.Tools.cross(direction, this.up);
var other = Tools.cross(direction, left); var other = L3D.Tools.cross(direction, left);
left.normalize(); left.normalize();
other.normalize(); other.normalize();
left = Tools.mul(left, this.size); left = L3D.Tools.mul(left, this.size);
other = Tools.mul(other, this.size); other = L3D.Tools.mul(other, this.size);
geometry.vertices.push(Tools.sum( Tools.sum( this.position, left), other), geometry.vertices.push(L3D.Tools.sum( L3D.Tools.sum( this.position, left), other),
Tools.diff(Tools.sum( this.position, other), left), L3D.Tools.diff(L3D.Tools.sum( this.position, other), left),
Tools.diff(Tools.diff(this.position, left), other), L3D.Tools.diff(L3D.Tools.diff(this.position, left), other),
Tools.sum( Tools.diff(this.position, other), left), L3D.Tools.sum( L3D.Tools.diff(this.position, other), left),
Tools.sum(this.position, direction) L3D.Tools.sum(this.position, direction)
); );
geometry.faces.push(new THREE.Face3(0,2,1), // new THREE.Face3(0,2,1), geometry.faces.push(new THREE.Face3(0,2,1), // new THREE.Face3(0,2,1),
@ -92,25 +92,25 @@ ArrowCamera.prototype.initExtremity = function() {
return this.mesh; return this.mesh;
}; };
ArrowCamera.prototype.updateExtremity = function() { L3D.BaseRecommendation.prototype.updateExtremity = function() {
var direction = this.target.clone(); var direction = this.target.clone();
direction.sub(this.position); direction.sub(this.position);
direction.normalize(); direction.normalize();
var left = Tools.cross(direction, this.up); var left = L3D.Tools.cross(direction, this.up);
var other = Tools.cross(direction, left); var other = L3D.Tools.cross(direction, left);
left.normalize(); left.normalize();
other.normalize(); other.normalize();
left = Tools.mul(left, this.size); left = L3D.Tools.mul(left, this.size);
other = Tools.mul(other, this.size); other = L3D.Tools.mul(other, this.size);
this.mesh.geometry.vertices = [ this.mesh.geometry.vertices = [
Tools.sum( Tools.sum( this.position, left), other), L3D.Tools.sum( L3D.Tools.sum( this.position, left), other),
Tools.diff(Tools.sum( this.position, other), left), L3D.Tools.diff(L3D.Tools.sum( this.position, other), left),
Tools.diff(Tools.diff(this.position, left), other), L3D.Tools.diff(L3D.Tools.diff(this.position, left), other),
Tools.sum( Tools.diff(this.position, other), left), L3D.Tools.sum( L3D.Tools.diff(this.position, other), left),
Tools.sum(this.position, direction) L3D.Tools.sum(this.position, direction)
]; ];
this.mesh.geometry.computeFaceNormals(); this.mesh.geometry.computeFaceNormals();
@ -118,15 +118,15 @@ ArrowCamera.prototype.updateExtremity = function() {
}; };
ArrowCamera.prototype.setSize = function(size) { L3D.BaseRecommendation.prototype.setSize = function(size) {
this.size = size; this.size = size;
this.updateExtremity(); this.updateExtremity();
}; };
// Update function // Update function
ArrowCamera.prototype.update = function(mainCamera) { L3D.BaseRecommendation.prototype.update = function(mainCamera) {
// Compute distance between center of camera and position // Compute distance between center of camera and position
dist = Tools.norm2(Tools.diff(mainCamera.position, this.center)); dist = L3D.Tools.norm2(L3D.Tools.diff(mainCamera.position, this.center));
var low_bound = 1; var low_bound = 1;
var high_bound = 5; var high_bound = 5;
@ -156,29 +156,29 @@ ArrowCamera.prototype.update = function(mainCamera) {
this.regenerateArrow(mainCamera); this.regenerateArrow(mainCamera);
}; };
ArrowCamera.prototype.regenerateArrow = function(mainCamera) { L3D.BaseRecommendation.prototype.regenerateArrow = function(mainCamera) {
var i; var i;
var vertices = []; var vertices = [];
// First point of curve // First point of curve
var f0 = mainCamera.position.clone(); var f0 = mainCamera.position.clone();
f0.add(Tools.mul(Tools.sum(new THREE.Vector3(0,-0.5,0), Tools.diff(this.target, this.position).normalize()),2)); f0.add(L3D.Tools.mul(L3D.Tools.sum(new THREE.Vector3(0,-0.5,0), L3D.Tools.diff(this.target, this.position).normalize()),2));
// Last point of curve // Last point of curve
var f1 = this.position.clone(); var f1 = this.position.clone();
// Last derivative of curve // Last derivative of curve
var fp1 = Tools.diff(this.target, this.position); var fp1 = L3D.Tools.diff(this.target, this.position);
fp1.normalize(); fp1.normalize();
fp1.multiplyScalar(2); fp1.multiplyScalar(2);
// Camera direction // Camera direction
var dir = Tools.diff(this.position, mainCamera.position); var dir = L3D.Tools.diff(this.position, mainCamera.position);
dir.normalize(); dir.normalize();
if (fp1.dot(dir) < -0.5) { if (fp1.dot(dir) < -0.5) {
// Regen polynom with better stuff // Regen polynom with better stuff
// var new_dir = Tools.cross(Tools.diff(this.position, mainCamera.position).normalize(), mainCamera.up); // var new_dir = L3D.Tools.cross(L3D.Tools.diff(this.position, mainCamera.position).normalize(), mainCamera.up);
// new_dir.multiplyScalar(new_dir.dot(fp1) < 0 ? 1 : -1); // new_dir.multiplyScalar(new_dir.dot(fp1) < 0 ? 1 : -1);
// new_dir.add(dir); // new_dir.add(dir);
// new_dir.add(dir); // new_dir.add(dir);
@ -195,7 +195,7 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
fp1.multiplyScalar(4); fp1.multiplyScalar(4);
var hermite = new Hermite.special.Polynom(f0, f1, fp1); var hermite = new L3D.Hermite.special.Polynom(f0, f1, fp1);
var up = this.up.clone(); var up = this.up.clone();
var point; var point;
@ -212,14 +212,14 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
up.normalize(); up.normalize();
var coeff = this.size / 2; var coeff = this.size / 2;
var left = Tools.cross(up, deriv); left.normalize(); left.multiplyScalar(coeff); var left = L3D.Tools.cross(up, deriv); left.normalize(); left.multiplyScalar(coeff);
var other = Tools.cross(deriv, left); other.normalize(); other.multiplyScalar(coeff); var other = L3D.Tools.cross(deriv, left); other.normalize(); other.multiplyScalar(coeff);
vertices.push( vertices.push(
Tools.sum(Tools.sum(point, left), other), L3D.Tools.sum(L3D.Tools.sum(point, left), other),
Tools.sum(Tools.diff(point, left), other), L3D.Tools.sum(L3D.Tools.diff(point, left), other),
Tools.diff(point, Tools.sum(other,left)), L3D.Tools.diff(point, L3D.Tools.sum(other,left)),
Tools.sum(Tools.diff(point, other), left) L3D.Tools.sum(L3D.Tools.diff(point, other), left)
); );
} }
@ -267,19 +267,19 @@ ArrowCamera.prototype.regenerateArrow = function(mainCamera) {
}; };
// Look function // Look function
ArrowCamera.prototype.look = function() { L3D.BaseRecommendation.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
ArrowCamera.prototype.addToScene = function(scene) { L3D.BaseRecommendation.prototype.addToScene = function(scene) {
scene.add(this); scene.add(this);
scene.add(this.object3D); scene.add(this.object3D);
}; };
ArrowCamera.prototype.traverse = function(callback) { L3D.BaseRecommendation.prototype.traverse = function(callback) {
this.object3D.traverse(callback); this.object3D.traverse(callback);
}; };
ArrowCamera.prototype.containsObject = function(object) { L3D.BaseRecommendation.prototype.containsObject = function(object) {
return object.parent === this.object3D; return object.parent === this.object3D;
}; };

View File

@ -1,9 +1,9 @@
// Initialization // Initialization
// class camera extends THREE.PerspectiveCamera // class camera extends THREE.PerspectiveCamera
var FixedCamera = function(arg1, arg2, arg3, arg4, position, target) { L3D.ArrowRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
ArrowCamera.apply(this, arguments); L3D.BaseRecommendation.apply(this, arguments);
}; };
FixedCamera.prototype = Object.create(ArrowCamera.prototype); L3D.ArrowRecommendation.prototype = Object.create(L3D.BaseRecommendation.prototype);
FixedCamera.prototype.constructor = FixedCamera; L3D.ArrowRecommendation.prototype.constructor = L3D.ArrowRecommendation;

View File

@ -1,7 +1,7 @@
// Initialization // Initialization
// class camera extends THREE.PerspectiveCamera // class camera extends THREE.PerspectiveCamera
var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) { L3D.ViewportRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
THREE.PerspectiveCamera.apply(this, arguments); THREE.PerspectiveCamera.apply(this, arguments);
// Set Position // Set Position
@ -21,7 +21,7 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
direction.normalize(); direction.normalize();
this.target = this.position.clone(); this.target = this.position.clone();
this.target.add(Tools.mul(direction,10)); this.target.add(L3D.Tools.mul(direction,10));
// this.up = new THREE.Vector3(0,0,1); // this.up = new THREE.Vector3(0,0,1);
// Compute corners // Compute corners
@ -30,17 +30,17 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
var left = Tools.cross(direction, this.up); var left = L3D.Tools.cross(direction, this.up);
var other = Tools.cross(direction, left); var other = L3D.Tools.cross(direction, left);
left.normalize(); left.normalize();
other.normalize(); other.normalize();
left = Tools.mul(left, 1); left = L3D.Tools.mul(left, 1);
other = Tools.mul(other, 1); other = L3D.Tools.mul(other, 1);
geometry.vertices.push(Tools.sum(Tools.sum(this.position, left), other), geometry.vertices.push(L3D.Tools.sum(L3D.Tools.sum(this.position, left), other),
Tools.diff(Tools.sum(this.position, other),left), L3D.Tools.diff(L3D.Tools.sum(this.position, other),left),
Tools.diff(Tools.diff(this.position, left),other), L3D.Tools.diff(L3D.Tools.diff(this.position, left),other),
Tools.sum(Tools.diff(this.position, other), left) L3D.Tools.sum(L3D.Tools.diff(this.position, other), left)
); );
geometry.faces.push(new THREE.Face3(0,1,2), // new THREE.Face3(0,2,1), geometry.faces.push(new THREE.Face3(0,1,2), // new THREE.Face3(0,2,1),
@ -50,28 +50,28 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
(function(self, direction, left, other) { (function(self, direction, left, other) {
var material = new THREE.LineBasicMaterial({ color: '0x000000'}); var material = new THREE.LineBasicMaterial({ color: '0x000000'});
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
var tmp_direction = Tools.mul(direction, -2); var tmp_direction = L3D.Tools.mul(direction, -2);
var target = Tools.sum(self.position, tmp_direction); var target = L3D.Tools.sum(self.position, tmp_direction);
// geometry.vertices.push(self.position, target); // geometry.vertices.push(self.position, target);
geometry.vertices.push( geometry.vertices.push(
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.diff(Tools.sum(self.position, other),left), L3D.Tools.diff(L3D.Tools.sum(self.position, other),left),
Tools.diff(Tools.diff(self.position, left),other), L3D.Tools.diff(L3D.Tools.diff(self.position, left),other),
Tools.sum(Tools.diff(self.position, other), left), L3D.Tools.sum(L3D.Tools.diff(self.position, other), left),
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.sum(Tools.diff(self.position, other), left), L3D.Tools.sum(L3D.Tools.diff(self.position, other), left),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.sum(self.position, other),left), L3D.Tools.diff(L3D.Tools.sum(self.position, other),left),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.diff(self.position, left),other), L3D.Tools.diff(L3D.Tools.diff(self.position, left),other),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.diff(self.position, other), left) L3D.Tools.sum(L3D.Tools.diff(self.position, other), left)
); );
self.line = new THREE.Line(geometry, material); self.line = new THREE.Line(geometry, material);
@ -88,17 +88,17 @@ var OldFixedCamera = function(arg1, arg2, arg3, arg4, position, target) {
this.mesh = new THREE.Mesh(geometry, material); this.mesh = new THREE.Mesh(geometry, material);
this.mesh.raycastable = true; this.mesh.raycastable = true;
}; };
OldFixedCamera.prototype = Object.create(THREE.PerspectiveCamera.prototype); L3D.ViewportRecommendation.prototype = Object.create(THREE.PerspectiveCamera.prototype);
OldFixedCamera.prototype.constructor = OldFixedCamera; L3D.ViewportRecommendation.prototype.constructor = L3D.ViewportRecommendation;
OldFixedCamera.prototype.check = function() { L3D.ViewportRecommendation.prototype.check = function() {
this.mesh.material.color.setHex(0x663366); this.mesh.material.color.setHex(0x663366);
}; };
// Update function // Update function
OldFixedCamera.prototype.update = function(position) { L3D.ViewportRecommendation.prototype.update = function(position) {
// Compute distance between center of camera and position // Compute distance between center of camera and position
dist = Tools.norm2(Tools.diff(position.position, this.position)); dist = L3D.Tools.norm2(L3D.Tools.diff(position.position, this.position));
var low_bound = 1; var low_bound = 1;
var high_bound = 5; var high_bound = 5;
@ -120,71 +120,71 @@ OldFixedCamera.prototype.update = function(position) {
}; };
// Look function // Look function
OldFixedCamera.prototype.look = function() { L3D.ViewportRecommendation.prototype.look = function() {
this.lookAt(this.target); this.lookAt(this.target);
}; };
OldFixedCamera.prototype.addToScene = function(scene) { L3D.ViewportRecommendation.prototype.addToScene = function(scene) {
scene.add(this); scene.add(this);
scene.add(this.mesh); scene.add(this.mesh);
scene.add(this.line); scene.add(this.line);
}; };
OldFixedCamera.prototype.traverse = function(callback) { L3D.ViewportRecommendation.prototype.traverse = function(callback) {
callback(this.mesh); callback(this.mesh);
callback(this.line); callback(this.line);
}; };
OldFixedCamera.prototype.containsObject = function(object) { L3D.ViewportRecommendation.prototype.containsObject = function(object) {
return object === this.mesh; return object === this.mesh;
}; };
OldFixedCamera.prototype.setSize = function(size) { L3D.ViewportRecommendation.prototype.setSize = function(size) {
var direction = this.target.clone(); var direction = this.target.clone();
direction.sub(this.position); direction.sub(this.position);
direction.normalize(); direction.normalize();
var left = Tools.cross(direction, this.up); var left = L3D.Tools.cross(direction, this.up);
var other = Tools.cross(direction, left); var other = L3D.Tools.cross(direction, left);
left.normalize(); left.normalize();
other.normalize(); other.normalize();
left = Tools.mul(left, size); left = L3D.Tools.mul(left, size);
other = Tools.mul(other, size); other = L3D.Tools.mul(other, size);
this.mesh.geometry.vertices = [ this.mesh.geometry.vertices = [
Tools.sum(Tools.sum(this.position, left), other), L3D.Tools.sum(L3D.Tools.sum(this.position, left), other),
Tools.diff(Tools.sum(this.position, other),left), L3D.Tools.diff(L3D.Tools.sum(this.position, other),left),
Tools.diff(Tools.diff(this.position, left),other), L3D.Tools.diff(L3D.Tools.diff(this.position, left),other),
Tools.sum(Tools.diff(this.position, other), left) L3D.Tools.sum(L3D.Tools.diff(this.position, other), left)
]; ];
this.mesh.geometry.verticesNeedUpdate = true; this.mesh.geometry.verticesNeedUpdate = true;
(function(self, direction, left, other, size) { (function(self, direction, left, other, size) {
var tmp_direction = Tools.mul(direction, -2 * size); var tmp_direction = L3D.Tools.mul(direction, -2 * size);
var target = Tools.sum(self.position, tmp_direction); var target = L3D.Tools.sum(self.position, tmp_direction);
var vertices = [ var vertices = [
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.diff(Tools.sum(self.position, other),left), L3D.Tools.diff(L3D.Tools.sum(self.position, other),left),
Tools.diff(Tools.diff(self.position, left),other), L3D.Tools.diff(L3D.Tools.diff(self.position, left),other),
Tools.sum(Tools.diff(self.position, other), left), L3D.Tools.sum(L3D.Tools.diff(self.position, other), left),
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.sum(Tools.diff(self.position, other), left), L3D.Tools.sum(L3D.Tools.diff(self.position, other), left),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.sum(self.position, left), other), L3D.Tools.sum(L3D.Tools.sum(self.position, left), other),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.sum(self.position, other),left), L3D.Tools.diff(L3D.Tools.sum(self.position, other),left),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.diff(Tools.diff(self.position, left),other), L3D.Tools.diff(L3D.Tools.diff(self.position, left),other),
Tools.sum(self.position, tmp_direction), L3D.Tools.sum(self.position, tmp_direction),
Tools.sum(Tools.diff(self.position, other), left) L3D.Tools.sum(L3D.Tools.diff(self.position, other), left)
]; ];
self.line.geometry.vertices = vertices; self.line.geometry.vertices = vertices;

View File

@ -1,45 +1,42 @@
// Initialization L3D.ReverseRecommendation = function(arg1, arg2, arg3, arg4, position, target) {
L3D.BaseRecommendation.apply(this, arguments);
// class camera extends THREE.PerspectiveCamera
var ReverseCamera = function(arg1, arg2, arg3, arg4, position, target) {
ArrowCamera.apply(this, arguments);
}; };
ReverseCamera.prototype = Object.create(ArrowCamera.prototype); L3D.ReverseRecommendation.prototype = Object.create(L3D.BaseRecommendation.prototype);
ReverseCamera.prototype.constructor = ReverseCamera; L3D.ReverseRecommendation.prototype.constructor = L3D.ReverseRecommendation;
// Overload init // Overload init
ReverseCamera.prototype.initExtremity = function() { L3D.ReverseRecommendation.prototype.initExtremity = function() {
var geometry = new THREE.Geometry(); var geometry = new THREE.Geometry();
var direction = this.target.clone(); var direction = this.target.clone();
direction.sub(this.position); direction.sub(this.position);
direction.normalize(); direction.normalize();
var left = Tools.cross(direction, this.up); var left = L3D.Tools.cross(direction, this.up);
var other = Tools.cross(direction, left); var other = L3D.Tools.cross(direction, left);
left.normalize(); left.normalize();
other.normalize(); other.normalize();
left = Tools.mul(left, this.size / 2 ); left = L3D.Tools.mul(left, this.size / 2 );
other = Tools.mul(other, this.size / 2); other = L3D.Tools.mul(other, this.size / 2);
var pyramidCenter = Tools.diff(this.position, Tools.mul(direction,0.25)); var pyramidCenter = L3D.Tools.diff(this.position, L3D.Tools.mul(direction,0.25));
geometry.vertices.push( geometry.vertices.push(
Tools.sum( Tools.sum( this.position, left), other), L3D.Tools.sum( L3D.Tools.sum( this.position, left), other),
Tools.diff(Tools.sum( this.position, other), left), L3D.Tools.diff(L3D.Tools.sum( this.position, other), left),
Tools.diff(Tools.diff(this.position, left), other), L3D.Tools.diff(L3D.Tools.diff(this.position, left), other),
Tools.sum( Tools.diff(this.position, other), left), L3D.Tools.sum( L3D.Tools.diff(this.position, other), left),
Tools.sum( Tools.sum( this.position, left), other), L3D.Tools.sum( L3D.Tools.sum( this.position, left), other),
Tools.diff(Tools.sum( this.position, other), left), L3D.Tools.diff(L3D.Tools.sum( this.position, other), left),
Tools.diff(Tools.diff(this.position, left), other), L3D.Tools.diff(L3D.Tools.diff(this.position, left), other),
Tools.sum( Tools.diff(this.position, other), left) L3D.Tools.sum( L3D.Tools.diff(this.position, other), left)
// Tools.diff(this.position, direction) // L3D.Tools.diff(this.position, direction)
); );
var lambda = 0.6; var lambda = 0.6;
for (var i = 0; i < 4; i++) for (var i = 0; i < 4; i++)
geometry.vertices[i] = Tools.mul(Tools.diff(geometry.vertices[i], Tools.mul(pyramidCenter,lambda)), 1/(1-lambda)); geometry.vertices[i] = L3D.Tools.mul(L3D.Tools.diff(geometry.vertices[i], L3D.Tools.mul(pyramidCenter,lambda)), 1/(1-lambda));
geometry.faces.push(new THREE.Face3(2,0,1), // new THREE.Face3(0,2,1), geometry.faces.push(new THREE.Face3(2,0,1), // new THREE.Face3(0,2,1),
@ -73,29 +70,29 @@ ReverseCamera.prototype.initExtremity = function() {
}; };
ReverseCamera.prototype.regenerateArrow = function(mainCamera) { L3D.ReverseRecommendation.prototype.regenerateArrow = function(mainCamera) {
var i; var i;
var vertices = []; var vertices = [];
// First point of curve // First point of curve
var f0 = mainCamera.position.clone(); var f0 = mainCamera.position.clone();
f0.add(Tools.mul(Tools.sum(new THREE.Vector3(0,-0.5,0), Tools.diff(this.target, this.position).normalize()),2)); f0.add(L3D.Tools.mul(L3D.Tools.sum(new THREE.Vector3(0,-0.5,0), L3D.Tools.diff(this.target, this.position).normalize()),2));
// Last point of curve // Last point of curve
var f1 = this.position.clone(); var f1 = this.position.clone();
// Last derivative of curve // Last derivative of curve
var fp1 = Tools.diff(this.target, this.position); var fp1 = L3D.Tools.diff(this.target, this.position);
fp1.normalize(); fp1.normalize();
fp1.multiplyScalar(2); fp1.multiplyScalar(2);
// Camera direction // Camera direction
var dir = Tools.diff(this.position, mainCamera.position); var dir = L3D.Tools.diff(this.position, mainCamera.position);
dir.normalize(); dir.normalize();
if (fp1.dot(dir) < -0.5) { if (fp1.dot(dir) < -0.5) {
// Regen polynom with better stuff // Regen polynom with better stuff
// var new_dir = Tools.cross(Tools.diff(this.position, mainCamera.position).normalize(), mainCamera.up); // var new_dir = L3D.Tools.cross(L3D.Tools.diff(this.position, mainCamera.position).normalize(), mainCamera.up);
// new_dir.multiplyScalar(new_dir.dot(fp1) < 0 ? 1 : -1); // new_dir.multiplyScalar(new_dir.dot(fp1) < 0 ? 1 : -1);
// new_dir.add(dir); // new_dir.add(dir);
// new_dir.add(dir); // new_dir.add(dir);
@ -112,7 +109,7 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
fp1.multiplyScalar(4); fp1.multiplyScalar(4);
var hermite = new Hermite.special.Polynom(f0, f1, fp1); var hermite = new L3D.Hermite.special.Polynom(f0, f1, fp1);
var up = this.up.clone(); var up = this.up.clone();
var point; var point;
@ -129,14 +126,14 @@ ReverseCamera.prototype.regenerateArrow = function(mainCamera) {
up.normalize(); up.normalize();
var coeff = i * i * this.size / 2; var coeff = i * i * this.size / 2;
var left = Tools.cross(up, deriv); left.normalize(); left.multiplyScalar(coeff); var left = L3D.Tools.cross(up, deriv); left.normalize(); left.multiplyScalar(coeff);
var other = Tools.cross(deriv, left); other.normalize(); other.multiplyScalar(coeff); var other = L3D.Tools.cross(deriv, left); other.normalize(); other.multiplyScalar(coeff);
vertices.push( vertices.push(
Tools.sum(Tools.sum(point, left), other), L3D.Tools.sum(L3D.Tools.sum(point, left), other),
Tools.sum(Tools.diff(point, left), other), L3D.Tools.sum(L3D.Tools.diff(point, left), other),
Tools.diff(point, Tools.sum(other,left)), L3D.Tools.diff(point, L3D.Tools.sum(other,left)),
Tools.sum(Tools.diff(point, other), left) L3D.Tools.sum(L3D.Tools.diff(point, other), left)
); );
} }

View File

@ -1,7 +1,6 @@
// Define RecommendedCamera if not defined var Recommendation = Recommendation || L3D.ArrowRecommendation;
var RecommendedCamera = RecommendedCamera || FixedCamera;
function addLight(scene) { L3D.addLight = function(scene) {
var directional_light = new THREE.DirectionalLight(0xdddddd); var directional_light = new THREE.DirectionalLight(0xdddddd);
directional_light.position.set(1, 2.5, 1).normalize(); directional_light.position.set(1, 2.5, 1).normalize();
directional_light.castShadow = false; directional_light.castShadow = false;
@ -11,9 +10,9 @@ function addLight(scene) {
scene.add(ambient_light); scene.add(ambient_light);
} }
function initPeachCastle(scene, collidableObjects, camera) { L3D.initPeachCastle = function(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry( var loader = new L3D.ProgressiveLoaderGeometry(
'/static/data/castle/princess peaches castle (outside).obj', '/static/data/castle/princess peaches castle (outside).obj',
scene, scene,
null, null,
@ -36,20 +35,20 @@ function initPeachCastle(scene, collidableObjects, camera) {
loader.obj.raycastable = true; loader.obj.raycastable = true;
} }
function resetPeachElements() { L3D.resetPeachElements = function() {
return { return {
position: new THREE.Vector3(0.24120226734236713,0.2009624547018851,-0.5998422840047036), position: new THREE.Vector3(0.24120226734236713,0.2009624547018851,-0.5998422840047036),
target: new THREE.Vector3(0.24120226734232672,0.20096245470190008,-40.5998422840047) target: new THREE.Vector3(0.24120226734232672,0.20096245470190008,-40.5998422840047)
}; };
} }
function initPeach(camera, scene, coins) { L3D.initPeach = function(camera, scene, coins) {
addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
initPeachCastle(scene, collidableObjects, camera); L3D.initPeachCastle(scene, collidableObjects, camera);
camera.resetElements = resetPeachElements(); camera.resetElements = L3D.resetPeachElements();
camera.collidableObjects = collidableObjects; camera.collidableObjects = collidableObjects;
camera.speed = 0.001; camera.speed = 0.001;
@ -60,12 +59,12 @@ function initPeach(camera, scene, coins) {
Coin.init(0.001); Coin.init(0.001);
var otherCams = []; var otherCams = [];
var cameras = new CameraContainer(camera, otherCams); var cameras = new L3D.CameraContainer(camera, otherCams);
return cameras; return cameras;
} }
function initZeldaScene(scene, collidableObjects, loader) { L3D.initZeldaScene = function(scene, collidableObjects, loader) {
// Create loader if not already done // Create loader if not already done
if (loader === undefined) { if (loader === undefined) {
loader = new THREE.OBJMTLLoader(); loader = new THREE.OBJMTLLoader();
@ -94,11 +93,11 @@ function initZeldaScene(scene, collidableObjects, loader) {
} }
function createPeachCameras(width, height) { L3D.createPeachCameras = function(width, height) {
var cams = []; var cams = [];
var createCamera = function(position, target) { var createCamera = function(position, target) {
return new RecommendedCamera( return new Recommendation(
50, 50,
width / height, width / height,
1, 1,
@ -121,8 +120,7 @@ function createPeachCameras(width, height) {
cams.push(createCamera( cams.push(createCamera(
new THREE.Vector3(2.625389073616235, 1.2252620948239699, -4.818718135555419), new THREE.Vector3(2.625389073616235, 1.2252620948239699, -4.818718135555419),
new THREE.Vector3(-19.756833131355208, -16.20027570329664, -33.02132017177813) new THREE.Vector3(-19.756833131355208, -16.20027570329664, -33.02132017177813)
));ader = new THREE.MTLLoader('/static/data/bobomb/'); ));
// loader.
// cams.push(createCamera( // cams.push(createCamera(
// new THREE.Vector3(1.3304975149911331, 0.4836093721106701, -8.60618907952783), // new THREE.Vector3(1.3304975149911331, 0.4836093721106701, -8.60618907952783),
@ -154,9 +152,9 @@ function createPeachCameras(width, height) {
return cams; return cams;
} }
function initBobombScene(scene, collidableObjects, camera) { L3D.initBobombScene = function(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry( var loader = new L3D.ProgressiveLoaderGeometry(
'/static/data/bobomb/bobomb battlefeild.obj', '/static/data/bobomb/bobomb battlefeild.obj',
scene, scene,
null, null,
@ -178,14 +176,14 @@ function initBobombScene(scene, collidableObjects, camera) {
} }
function resetBobombElements() { L3D.resetBobombElements = function() {
return { return {
position: new THREE.Vector3(38.115627509754646,10.829803024792419,-19.862035691341315), position: new THREE.Vector3(38.115627509754646,10.829803024792419,-19.862035691341315),
target: new THREE.Vector3(-1.4518898576752122,5.048214777643772,-18.869661407832535) target: new THREE.Vector3(-1.4518898576752122,5.048214777643772,-18.869661407832535)
}; };
} }
function createBobombCoins() { L3D.createBobombCoins = function() {
var coins = []; var coins = [];
coins.push( coins.push(
@ -202,11 +200,11 @@ function createBobombCoins() {
return coins; return coins;
} }
function createBobombCameras(width, height) { L3D.createBobombCameras = function(width, height) {
var cams = []; var cams = [];
var createCamera = function(position, target) { var createCamera = function(position, target) {
return new RecommendedCamera( return new Recommendation(
50, 50,
width / height, width / height,
1, 1,
@ -267,13 +265,13 @@ function createBobombCameras(width, height) {
} }
function initBobomb(camera, scene, coins) { L3D.initBobomb = function(camera, scene, coins) {
addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
initBobombScene(scene, collidableObjects, camera); L3D.initBobombScene(scene, collidableObjects, camera);
camera.resetElements = resetBobombElements(); camera.resetElements = L3D.resetBobombElements();
camera.collidableObjects = collidableObjects; camera.collidableObjects = collidableObjects;
camera.speed = 0.005; camera.speed = 0.005;
@ -283,14 +281,14 @@ function initBobomb(camera, scene, coins) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
var tmp = createBobombCoins(); var tmp = L3D.createBobombCoins();
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
} }
var otherCams = createBobombCameras(container_size.width(), container_size.height()); var otherCams = L3D.createBobombCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new L3D.CameraContainer(camera, otherCams);
otherCams.forEach(function(cam) {cam.addToScene(scene);}); otherCams.forEach(function(cam) {cam.addToScene(scene);});
@ -299,9 +297,9 @@ function initBobomb(camera, scene, coins) {
return cameras; return cameras;
} }
function initWhompScene(scene, collidableObjects, camera) { L3D.initWhompScene = function(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry( var loader = new L3D.ProgressiveLoaderGeometry(
'/static/data/whomp/Whomps Fortress.obj', '/static/data/whomp/Whomps Fortress.obj',
scene, scene,
null, null,
@ -353,11 +351,11 @@ function initWhompScene(scene, collidableObjects, camera) {
loader.obj.raycastable = true; loader.obj.raycastable = true;
} }
function createWhompCameras(width, height) { L3D.createWhompCameras = function(width, height) {
var cams = []; var cams = [];
var createCamera = function(position, target) { var createCamera = function(position, target) {
return new RecommendedCamera( return new Recommendation(
50, 50,
width / height, width / height,
1, 1,
@ -419,7 +417,7 @@ function createWhompCameras(width, height) {
return cams; return cams;
} }
function createWhompCoins() { L3D.createWhompCoins = function() {
return [ return [
new Coin(-5.529176900669821,2.886514571524507,4.127968972716147), new Coin(-5.529176900669821,2.886514571524507,4.127968972716147),
new Coin(-3.336263561768484,9.341710952326468,1.0230063543998414), new Coin(-3.336263561768484,9.341710952326468,1.0230063543998414),
@ -432,20 +430,20 @@ function createWhompCoins() {
]; ];
} }
function resetWhompElements() { L3D.resetWhompElements = function() {
return { return {
position : new THREE.Vector3(-6.725817925071645,1.4993570618328055,-10.356480813212423), position : new THREE.Vector3(-6.725817925071645,1.4993570618328055,-10.356480813212423),
target : new THREE.Vector3(-4.8541705829784604,1.3192268872752742,-6.825972443720941) target : new THREE.Vector3(-4.8541705829784604,1.3192268872752742,-6.825972443720941)
}; };
} }
function initWhomp(camera, scene, coins) { L3D.initWhomp = function(camera, scene, coins) {
addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
initWhompScene(scene, collidableObjects, camera); L3D.initWhompScene(scene, collidableObjects, camera);
camera.resetElements = resetWhompElements(); camera.resetElements = L3D.resetWhompElements();
camera.collidableObjects = collidableObjects; camera.collidableObjects = collidableObjects;
camera.speed = 0.002; camera.speed = 0.002;
@ -455,14 +453,14 @@ function initWhomp(camera, scene, coins) {
scene.add(camera); scene.add(camera);
Coin.init(0.002); Coin.init(0.002);
var tmp = createWhompCoins(); var tmp = L3D.createWhompCoins();
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
} }
var otherCams = createWhompCameras(container_size.width(), container_size.height()); var otherCams = L3D.createWhompCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new L3D.CameraContainer(camera, otherCams);
otherCams.forEach(function(cam) {cam.addToScene(scene);}); otherCams.forEach(function(cam) {cam.addToScene(scene);});
@ -471,9 +469,9 @@ function initWhomp(camera, scene, coins) {
return cameras; return cameras;
} }
function initMountainScene(scene, collidableObjects, camera) { L3D.initMountainScene = function(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry( var loader = new L3D.ProgressiveLoaderGeometry(
'/static/data/mountain/coocoolmountain.obj', '/static/data/mountain/coocoolmountain.obj',
scene, scene,
null, null,
@ -503,7 +501,7 @@ function initMountainScene(scene, collidableObjects, camera) {
collidableObjects.push(loader.obj); collidableObjects.push(loader.obj);
} }
function createMountainCoins() { L3D.createMountainCoins = function() {
return [ return [
new Coin(-18.766484229298513,-6.174512332611151,16.379061147364553), new Coin(-18.766484229298513,-6.174512332611151,16.379061147364553),
new Coin(-22.48878786991581,-17.698282433679474,1.6030258853572397), new Coin(-22.48878786991581,-17.698282433679474,1.6030258853572397),
@ -516,11 +514,11 @@ function createMountainCoins() {
]; ];
} }
function createMountainCameras(width, height) { L3D.createMountainCameras = function(width, height) {
var cams = []; var cams = [];
var createCamera = function(position, target) { var createCamera = function(position, target) {
return new RecommendedCamera( return new Recommendation(
50, 50,
width / height, width / height,
1, 1,
@ -584,20 +582,20 @@ function createMountainCameras(width, height) {
return cams; return cams;
} }
function resetMountainElements() { L3D.resetMountainElements = function() {
return { return {
position : new THREE.Vector3(-20.558328115300082,23.601312087942762,-10.220633604814038), position : new THREE.Vector3(-20.558328115300082,23.601312087942762,-10.220633604814038),
target : new THREE.Vector3(11.025356711105232,11.969889531789319,11.393733425161644) target : new THREE.Vector3(11.025356711105232,11.969889531789319,11.393733425161644)
}; };
} }
function initMountain(camera, scene, coins) { L3D.initMountain = function(camera, scene, coins) {
addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
initMountainScene(scene, collidableObjects, camera); L3D.initMountainScene(scene, collidableObjects, camera);
camera.resetElements = resetMountainElements(); camera.resetElements = L3D.resetMountainElements();
camera.collidableObjects = collidableObjects; camera.collidableObjects = collidableObjects;
camera.speed = 0.005; camera.speed = 0.005;
@ -607,14 +605,14 @@ function initMountain(camera, scene, coins) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
var tmp = createMountainCoins(); var tmp = L3D.createMountainCoins();
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
} }
var otherCams = createMountainCameras(container_size.width(), container_size.height()); var otherCams = L3D.createMountainCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new L3D.CameraContainer(camera, otherCams);
otherCams.forEach(function(cam) {cam.addToScene(scene);}); otherCams.forEach(function(cam) {cam.addToScene(scene);});
@ -622,20 +620,25 @@ function initMountain(camera, scene, coins) {
return cameras; return cameras;
} }
function initSponzaScene(scene, collidableObjects, camera) { L3D.initSponzaScene = function(scene, collidableObjects, camera) {
var loader = new ProgressiveLoaderGeometry('/static/data/sponza/sponza.obj', scene, camera, function(obj) { var loader = new L3D.ProgressiveLoaderGeometry(
if (obj.material.name === 'chain' || '/static/data/sponza/sponza.obj',
obj.material.name === 'leaf' || scene,
obj.material.name === 'Material__57') { camera,
function(obj) {
if (obj.material.name === 'chain' ||
obj.material.name === 'leaf' ||
obj.material.name === 'Material__57') {
THREEx.Transparency.push(obj); THREEx.Transparency.push(obj);
}
obj.raycastable = true;
} }
);
obj.raycastable = true;
});
l = loader; l = loader;
loader.load(); loader.load();
@ -685,29 +688,29 @@ function initSponzaScene(scene, collidableObjects, camera) {
} }
function createSponzaCoins() { L3D.createSponzaCoins = function() {
return []; return [];
} }
function createSponzaCameras() { L3D.createSponzaCameras = function() {
return []; return [];
} }
function resetSponzaElements() { L3D.resetSponzaElements = function() {
return { return {
position: new THREE.Vector3(92.98373669520107,60.8877777990862,11.130138641670737), position: new THREE.Vector3(92.98373669520107,60.8877777990862,11.130138641670737),
target: new THREE.Vector3(53.76696417668598,56.09739213575453,4.877382575136091) target: new THREE.Vector3(53.76696417668598,56.09739213575453,4.877382575136091)
}; };
} }
function initSponza(camera, scene, coins) { L3D.initSponza = function(camera, scene, coins) {
addLight(scene); L3D.addLight(scene);
var collidableObjects = []; var collidableObjects = [];
initSponzaScene(scene, collidableObjects, camera); L3D.initSponzaScene(scene, collidableObjects, camera);
camera.resetElements = resetSponzaElements(); camera.resetElements = L3D.resetSponzaElements();
camera.collidableObjects = collidableObjects; camera.collidableObjects = collidableObjects;
camera.speed = 0.05; camera.speed = 0.05;
@ -717,14 +720,14 @@ function initSponza(camera, scene, coins) {
scene.add(camera); scene.add(camera);
Coin.init(); Coin.init();
var tmp = createSponzaCoins(); var tmp = L3D.createSponzaCoins();
for (var i in tmp) { for (var i in tmp) {
coins.push(tmp[i]); coins.push(tmp[i]);
} }
var otherCams = createSponzaCameras(container_size.width(), container_size.height()); var otherCams = L3D.createSponzaCameras(container_size.width(), container_size.height());
var cameras = new CameraContainer(camera, otherCams); var cameras = new L3D.CameraContainer(camera, otherCams);
otherCams.forEach(function(cam) {cam.addToScene(scene);}); otherCams.forEach(function(cam) {cam.addToScene(scene);});

View File

@ -1,4 +1,4 @@
var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) { L3D.CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.raycaster = new THREE.Raycaster(); this.raycaster = new THREE.Raycaster();
this.renderer = renderer; this.renderer = renderer;
this.mouse = {}; this.mouse = {};
@ -9,7 +9,7 @@ var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.coins = coins; this.coins = coins;
}; };
CameraSelecter.prototype.pointedCamera = function() { L3D.CameraSelecter.prototype.pointedCamera = function() {
var returnCamera; var returnCamera;
var x = ( this.mouse.x / this.renderer.domElement.width ) * 2 - 1; var x = ( this.mouse.x / this.renderer.domElement.width ) * 2 - 1;
@ -66,7 +66,7 @@ CameraSelecter.prototype.pointedCamera = function() {
this.currentPointedCamera = null; this.currentPointedCamera = null;
}; };
CameraSelecter.prototype.update = function(event, y) { L3D.CameraSelecter.prototype.update = function(event, y) {
var e; var e;
if (event !== undefined) { if (event !== undefined) {
@ -85,7 +85,7 @@ CameraSelecter.prototype.update = function(event, y) {
if (hovered !== undefined && !(hovered instanceof Coin)) { if (hovered !== undefined && !(hovered instanceof Coin)) {
if (hovered !== previousCamera) { if (hovered !== previousCamera) {
// log it // log it
e = new BD.Event.Hovered(); e = new L3D.BD.Event.Hovered();
e.start = true; e.start = true;
e.arrow_id = this.cameras.cameras.indexOf(this.currentPointedCamera); e.arrow_id = this.cameras.cameras.indexOf(this.currentPointedCamera);
e.send(); e.send();
@ -98,7 +98,7 @@ CameraSelecter.prototype.update = function(event, y) {
} else { } else {
if (this.prev.go) { if (this.prev.go) {
// Log if previous was not null // Log if previous was not null
e = new BD.Event.Hovered(); e = new L3D.BD.Event.Hovered();
e.start = false; e.start = false;
e.arrow_id = null; e.arrow_id = null;
e.send(); e.send();
@ -109,17 +109,17 @@ CameraSelecter.prototype.update = function(event, y) {
document.getElementById('container').style.cursor = hovered ? "pointer" : "auto"; document.getElementById('container').style.cursor = hovered ? "pointer" : "auto";
if (this.cameras.mainCamera().pointerLocked) if (this.cameras.mainCamera().pointerLocked)
this.cameras.mainCamera().mousePointer.render(hovered ? MousePointer.RED : MousePointer.BLACK); this.cameras.mainCamera().mousePointer.render(hovered ? L3D.MousePointer.RED : L3D.MousePointer.BLACK);
}; };
CameraSelecter.prototype.click = function(event) { L3D.CameraSelecter.prototype.click = function(event) {
var e; var e;
var newCamera = this.pointedCamera(); var newCamera = this.pointedCamera();
if (newCamera !== undefined && !(newCamera instanceof Coin)) { if (newCamera !== undefined && !(newCamera instanceof Coin)) {
e = new BD.Event.ArrowClicked(); e = new L3D.BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera); e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send(); e.send();
@ -130,7 +130,7 @@ CameraSelecter.prototype.click = function(event) {
} else if (newCamera instanceof Coin) { } else if (newCamera instanceof Coin) {
// Coin found, notify server // Coin found, notify server
e = new BD.Event.CoinClicked(); e = new L3D.BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera); e.coin_id = this.coins.indexOf(newCamera);
e.send(); e.send();
newCamera.get(); newCamera.get();
@ -139,7 +139,7 @@ CameraSelecter.prototype.click = function(event) {
}; };
CameraSelecter.prototype.clickPointer = function(event) { L3D.CameraSelecter.prototype.clickPointer = function(event) {
var e; var e;
if (this.cameras.mainCamera().pointerLocked) { if (this.cameras.mainCamera().pointerLocked) {
@ -148,7 +148,7 @@ CameraSelecter.prototype.clickPointer = function(event) {
if (newCamera !== undefined && !(newCamera instanceof Coin)) { if (newCamera !== undefined && !(newCamera instanceof Coin)) {
e = new BD.Event.ArrowClicked(); e = new L3D.BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera); e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send(); e.send();
@ -159,7 +159,7 @@ CameraSelecter.prototype.clickPointer = function(event) {
} else if (newCamera instanceof Coin) { } else if (newCamera instanceof Coin) {
// Coin found, notify server // Coin found, notify server
e = new BD.Event.CoinClicked(); e = new L3D.BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera); e.coin_id = this.coins.indexOf(newCamera);
e.send(); e.send();
newCamera.get(); newCamera.get();

View File

@ -1,8 +1,9 @@
/** /**
* Represents the history of an object * Represents the history of an object
* @constructor * @constructor
* @memberOf L3D
*/ */
var History = function() { L3D.History = function() {
/** /**
* Stores the different states of the object * Stores the different states of the object
* @type {Object[]} * @type {Object[]}
@ -26,7 +27,7 @@ var History = function() {
* Appends a new state at the end of the history * Appends a new state at the end of the history
* @param {Object} state the state to append * @param {Object} state the state to append
*/ */
History.prototype.addState = function(state) { L3D.History.prototype.addState = function(state) {
++this.index; ++this.index;
this.size = this.index + 1; this.size = this.index + 1;
this.states[this.size-1] = state; this.states[this.size-1] = state;
@ -35,7 +36,7 @@ History.prototype.addState = function(state) {
/** /**
* Returns the previous state and change the index to the previous state (so you can redo) * Returns the previous state and change the index to the previous state (so you can redo)
*/ */
History.prototype.undo = function() { L3D.History.prototype.undo = function() {
if (this.undoable()) { if (this.undoable()) {
this.index--; this.index--;
return this.currentState(); return this.currentState();
@ -45,7 +46,7 @@ History.prototype.undo = function() {
/** /**
* Returns the next state and change the index to the next state (so you can re-undo) * Returns the next state and change the index to the next state (so you can re-undo)
*/ */
History.prototype.redo = function() { L3D.History.prototype.redo = function() {
if (this.redoable()) { if (this.redoable()) {
this.index++; this.index++;
return this.currentState(); return this.currentState();
@ -56,7 +57,7 @@ History.prototype.redo = function() {
* Checks if there is a undo possibility * Checks if there is a undo possibility
* @returns {Boolean} true if undo is possible, false otherwise * @returns {Boolean} true if undo is possible, false otherwise
*/ */
History.prototype.undoable = function() { L3D.History.prototype.undoable = function() {
return this.index > 0; return this.index > 0;
}; };
@ -64,7 +65,7 @@ History.prototype.undoable = function() {
* Checks if there is a redo possibility * Checks if there is a redo possibility
* @returns {Boolean} true if redo is possible, false otherwise * @returns {Boolean} true if redo is possible, false otherwise
*/ */
History.prototype.redoable = function() { L3D.History.prototype.redoable = function() {
return this.index < this.size - 1; return this.index < this.size - 1;
}; };
@ -72,6 +73,6 @@ History.prototype.redoable = function() {
* Returns the current state in the history * Returns the current state in the history
* @returns {Object} the current state in the history * @returns {Object} the current state in the history
*/ */
History.prototype.currentState = function() { L3D.History.prototype.currentState = function() {
return this.states[this.index]; return this.states[this.index];
}; };

View File

@ -1,4 +1,4 @@
var utils = (function() { L3D.utils = (function() {
var utils = {}; var utils = {};

View File

@ -1,9 +1,9 @@
var BD = {}; L3D.BD = {};
BD.Private = {}; L3D.BD.Private = {};
BD.Private.sendData = function(url, data) { L3D.BD.Private.sendData = function(url, data) {
if (BD.Private.enabled) { if (L3D.BD.Private.enabled) {
// Append time to data // Append time to data
data.time = Date.now() / 1000; data.time = Date.now() / 1000;
@ -21,17 +21,17 @@ BD.Private.sendData = function(url, data) {
} }
}; };
BD.Private.enabled = true; L3D.BD.Private.enabled = true;
BD.enable = function() { L3D.BD.enable = function() {
BD.Private.enabled = true; L3D.BD.Private.enabled = true;
}; };
BD.disable = function() { L3D.BD.disable = function() {
BD.Private.enabled = false; L3D.BD.Private.enabled = false;
}; };
BD.Private.compactCamera = function(camera) { L3D.BD.Private.compactCamera = function(camera) {
return { return {
position: { position: {
x: camera.position.x, x: camera.position.x,
@ -46,71 +46,71 @@ BD.Private.compactCamera = function(camera) {
}; };
}; };
BD.Event = {}; L3D.BD.Event = {};
BD.Event.ArrowClicked = function() {}; L3D.BD.Event.ArrowClicked = function() {};
BD.Event.ArrowClicked.prototype.send = function() { L3D.BD.Event.ArrowClicked.prototype.send = function() {
var url = "/arrow-clicked"; var url = "/arrow-clicked";
var data = {arrow_id: this.arrow_id}; var data = {arrow_id: this.arrow_id};
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.CoinClicked = function() {}; L3D.BD.Event.CoinClicked = function() {};
BD.Event.CoinClicked.prototype.send = function() { L3D.BD.Event.CoinClicked.prototype.send = function() {
var url = "/coin-clicked"; var url = "/coin-clicked";
var data = {coin_id: this.coin_id}; var data = {coin_id: this.coin_id};
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.KeyboardEvent = function() {}; L3D.BD.Event.KeyboardEvent = function() {};
BD.Event.KeyboardEvent.prototype.send = function() { L3D.BD.Event.KeyboardEvent.prototype.send = function() {
var url = "/keyboard-event"; var url = "/keyboard-event";
var data = { var data = {
camera: BD.Private.compactCamera(this.camera) camera: L3D.BD.Private.compactCamera(this.camera)
}; };
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.ResetClicked = function() {}; L3D.BD.Event.ResetClicked = function() {};
BD.Event.ResetClicked.prototype.send = function() { L3D.BD.Event.ResetClicked.prototype.send = function() {
var url = "/reset-clicked"; var url = "/reset-clicked";
var data = {}; var data = {};
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.PreviousNextClicked = function() {}; L3D.BD.Event.PreviousNextClicked = function() {};
BD.Event.PreviousNextClicked.prototype.send = function() { L3D.BD.Event.PreviousNextClicked.prototype.send = function() {
var url = "/previous-next-clicked"; var url = "/previous-next-clicked";
var data = { var data = {
// casts previous to boolean // casts previous to boolean
previous: this.previous, previous: this.previous,
camera: BD.Private.compactCamera(this.camera) camera: L3D.BD.Private.compactCamera(this.camera)
}; };
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.Hovered = function() {}; L3D.BD.Event.Hovered = function() {};
BD.Event.Hovered.prototype.send = function() { L3D.BD.Event.Hovered.prototype.send = function() {
var url = "/hovered"; var url = "/hovered";
var data = { var data = {
start: this.start, start: this.start,
arrow_id: this.arrow_id arrow_id: this.arrow_id
}; };
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };
BD.Event.Fps = function() {}; L3D.BD.Event.Fps = function() {};
BD.Event.Fps.prototype.send = function() { L3D.BD.Event.Fps.prototype.send = function() {
var url = "/fps"; var url = "/fps";
var data = { var data = {
fps: this.fps fps: this.fps
}; };
BD.Private.sendData(url, data); L3D.BD.Private.sendData(url, data);
}; };

View File

@ -1,19 +1,19 @@
var Displayable = function() { L3D.Displayable = function() {
// Nothing to do here // Nothing to do here
}; };
Displayable.prototype.addToScene = function(scene) { L3D.Displayable.prototype.addToScene = function(scene) {
scene.add(this.mesh); scene.add(this.mesh);
}; };
Displayable.prototype.translate = function(x,y,z) { L3D.Displayable.prototype.translate = function(x,y,z) {
this.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(x,y,z)); this.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(x,y,z));
}; };
// class Cube extends Displayable // class L3D.Cube extends L3D.Displayable
var Cube = function(size, style) { L3D.Cube = function(size, style) {
// Super constructor call // Super constructor call
Displayable.call(this); L3D.Displayable.call(this);
if (size === undefined) size = 100; if (size === undefined) size = 100;
if (style === undefined) style = {}; if (style === undefined) style = {};
@ -25,12 +25,12 @@ var Cube = function(size, style) {
this.mesh = new THREE.Mesh(this.geometry, this.material); this.mesh = new THREE.Mesh(this.geometry, this.material);
this.mesh.castShadow = false; this.mesh.castShadow = false;
}; };
Cube.prototype = Object.create(Displayable.prototype); L3D.Cube.prototype = Object.create(L3D.Displayable.prototype);
Cube.prototype.constructor = Cube; L3D.Cube.prototype.constructor = L3D.Cube;
// class Plane extends Displayable // class L3D.Plane extends L3D.Displayable
var Plane = function(size1, size2, style) { L3D.Plane = function(size1, size2, style) {
Displayable.call(this); L3D.Displayable.call(this);
if (style === undefined) style = {}; if (style === undefined) style = {};
@ -41,9 +41,9 @@ var Plane = function(size1, size2, style) {
this.mesh.receiveShadow = true; this.mesh.receiveShadow = true;
}; };
Plane.prototype = Object.create(Displayable.prototype); L3D.Plane.prototype = Object.create(L3D.Displayable.prototype);
Plane.prototype.constructor = Plane; L3D.Plane.prototype.constructor = L3D.Plane;
Plane.prototype.addToScene = function(scene) { L3D.Plane.prototype.addToScene = function(scene) {
scene.add(this.mesh); scene.add(this.mesh);
}; };