Skip to content

Commit

Permalink
Added proper hover animation (scale)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminluck committed Jun 5, 2017
1 parent 5553437 commit 09e5454
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
10 changes: 8 additions & 2 deletions js/components/InputController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function detachIOEventListeners(){
}

function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
Expand All @@ -40,12 +40,17 @@ function onMouseMove( event ) {
document.body.style.cursor = 'default';

if ( intersects.length > 0 ) {

var mesh = intersects[0].object.parent;
window.lastMesh = mesh;
WiggleMeshIn(mesh);
// mesh.rotateY(0.1);
document.body.style.cursor = 'pointer';

}else{
if(window.lastMesh){
WiggleMeshOut(window.lastMesh);
}
}



Expand All @@ -56,6 +61,7 @@ function onTouchEnd(event){
onTouchStart(event);
}


function onTouchStart(event){
console.log(event);
if(event.targetTouches){
Expand Down
1 change: 1 addition & 0 deletions js/components/StateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var StateManager = (function () {
name:"splash",
ready: false,
init: function(){
getInitialRotationForObjects();
self.drawSplash();
},
destroy: function(){
Expand Down
2 changes: 1 addition & 1 deletion js/components/world/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ function init() {
}

window.addEventListener( 'resize', onWindowResize, false );

console.log(scene);

}
91 changes: 91 additions & 0 deletions js/components/world/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,94 @@ function render() {
THREE.AnimationHandler.update( clock.getDelta() );
renderer.render( scene, camera );
}

function getInitialRotationForObjects(){
console.log(scene);
window.initialObjectRotations = {};
window.SoundManager.songs.forEach(function(item){
var mesh = window.scene.getObjectByName(item.name);
if(mesh){
window.initialObjectRotations[item.name] = mesh.rotation;
}
});
}

function getMeshByTarget(mesh){
meshName = mesh.name;
meshName = meshName.replace("invis_", "");
mesh = scene.getObjectByName(meshName);
return mesh;
}

function WiggleMeshIn(mesh){
//debugger;
// find the actual mesh
actualMesh = getMeshByTarget(mesh);
meshName = actualMesh.name;
// mesh.rotateX(-0.005);
if(actualMesh.isAnimating != 'in'){
// animateRotation(meshName,0, window.initialObjectRotations[meshName].y, actualMesh.rotation.y + 0.5, 200, 'in');
// animateMethod(meshName,'rotateY',0, 0, 0.005, 200, 'in');
animateScale(meshName, 0, 1, 1.25, 250, 'in');
}
console.log(mesh);
}

function animateRotation(meshName,unit,from,to,time, status) {
elem = scene.getObjectByName(meshName);
if(!elem) return;
var start = new Date().getTime(),
timer = setInterval(function() {
var step = Math.min(1,(new Date().getTime()-start)/time);
elem['rotation']['y'] = (from+step*(to-from))+unit;
if( step == 1){ clearInterval(timer); elem.isAnimating = status;}
},25);
elem.isAnimating = status;
console.log(elem.isAnimating);
elem['rotation']['x'] = from+unit;
}

function animateScale(meshName,unit,from,to,time, status) {
elem = scene.getObjectByName(meshName);
if(!elem) return;
var start = new Date().getTime(),
timer = setInterval(function() {
var step = Math.min(1,(new Date().getTime()-start)/time);
elem['scale']['x'] = (from+step*(to-from))+unit;
elem['scale']['y'] = (from+step*(to-from))+unit;
elem['scale']['z'] = (from+step*(to-from))+unit;
if( step == 1){ clearInterval(timer); elem.isAnimating = status;}
},25);
elem.isAnimating = status;
console.log(elem.isAnimating);
elem['scale']['x'] = from+unit;
elem['scale']['y'] = from+unit;
elem['scale']['z'] = from+unit;
}

function animateMethod(meshName,method,unit,from,to,time,status) {
elem = scene.getObjectByName(meshName);
if(!elem) return;
var start = new Date().getTime(),
timer = setInterval(function() {
var step = Math.min(1,(new Date().getTime()-start)/time);
elem[method]((from+step*(to-from))+unit);
if( step == 1){ clearInterval(timer); elem.isAnimating = status;}
},25);
elem[method](from+unit);
}

function WiggleMeshOut(mesh){
// debugger;
actualMesh = getMeshByTarget(mesh);
meshName = actualMesh.name;

// mesh.rotateX(-0.005);
if(actualMesh.isAnimating != 'out'){
// animateRotation(meshName,0, actualMesh.rotation.y, window.initialObjectRotations[meshName].y, 200, 'out');
// animateMethod(meshName,'rotateY',0, 0, -0.005, 200, 'out');
animateScale(meshName, 0, 1.25, 1, 250, 'out');
}
console.log(actualMesh.rotation.x);
//
}
2 changes: 1 addition & 1 deletion js/components/world/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ window.addEventListener( 'deviceorientation', function(event){
item.children[0].material = symbolMeshMaterial;
item.children.forEach(function(mesh){

if(mesh.children[0]){
if(mesh.children[0]){
mesh.material = symbolMeshMaterial;
if(mesh.children[0]){
var innerMesh = mesh.children[0];
Expand Down

0 comments on commit 09e5454

Please sign in to comment.