Skip to content

Instantly share code, notes, and snippets.

@omarojo
Created June 14, 2018 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarojo/0ef4801c2ba03fef1ff4eabb2ece79b3 to your computer and use it in GitHub Desktop.
Save omarojo/0ef4801c2ba03fef1ff4eabb2ece79b3 to your computer and use it in GitHub Desktop.
Animate an Object
// ----------- API -------------
const D = require('Diagnostics');
const Scene = require('Scene');
const FT = require('FaceTracking');
const FGestures = require('FaceGestures');
const A = require('Animation');
const R = require('Reactive');
const Time = require('Time');
var objToAnimate = Scene.root.find("plane0");
var isUp = false
FGestures.hasMouthOpen(FT.face(0)).monitor().subscribe(function(changedValue){
if(changedValue.newValue && isUp == false ){//if mouth is open and object is NOT up
D.log("OPEN")
moveObjectUp()
}
});
FGestures.hasEyebrowsRaised(FT.face(0)).monitor().subscribe(function(changedValue){
if(changedValue.newValue && isUp == true){ //if eyesbrows were raised and object is already UP
moveObjectDown()
}
});
function moveObjectUp(){
var tDriver = A.timeDriver({"durationMilliseconds":1000});
var samplerX = A.samplers.linear(0, 10);
var samplerY = A.samplers.linear(0, 10);
var samplerZ = A.samplers.linear(0, 10);
objToAnimate.transform.x = A.animate(tDriver, samplerX);
objToAnimate.transform.y = A.animate(tDriver, samplerY);
objToAnimate.transform.z = A.animate(tDriver, samplerZ);
tDriver.onCompleted().subscribe(function(){
isUp = true
});
tDriver.start()
}
function moveObjectDown(){
var tDriver = A.timeDriver({"durationMilliseconds":1000});
var samplerX = A.samplers.linear(10, 0);
var samplerY = A.samplers.linear(10, 0);
var samplerZ = A.samplers.linear(10, 0);
objToAnimate.transform.x = A.animate(tDriver, samplerX);
objToAnimate.transform.y = A.animate(tDriver, samplerY);
objToAnimate.transform.z = A.animate(tDriver, samplerZ);
tDriver.onCompleted().subscribe(function(){
isUp = false
});
tDriver.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment