Created
November 30, 2019 23:22
-
-
Save yearofthewhopper/3e793ae8bedafdf28d14236faee9b0c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Materials = require('Materials'); | |
const Textures = require('Textures'); | |
const Scene = require('Scene'); | |
const TouchGestures = require('TouchGestures'); | |
const Animation = require('Animation'); | |
// Locate the plane in the Scene | |
const plane = Scene.root.find('plane0'); | |
//animation has 5 frames and is imported into a material called "material0" | |
//Material0 is applied to plane0 in the scene | |
//tapGestures is enabled from the user-preferences menu | |
//animation sequence name is animationsSequence0 | |
const timeDriverParameters = { | |
// The duration of the driver | |
durationMilliseconds: 3000, | |
// The number of iterations before the driver stops | |
loopCount: 1, | |
mirror: true | |
}; | |
const animationSequence0 = Textures.get("animationSequence0"); | |
const material = Materials.get('material0'); | |
plane.material = material; | |
const timeDriver = Animation.timeDriver(timeDriverParameters); | |
const handSequenceFrameSampler = Animation.samplers.sequence( | |
{ | |
samplers: [ | |
Animation.samplers.linear(0, 5), | |
Animation.samplers.linear(5, 5), | |
Animation.samplers.linear(5, 0), | |
Animation.samplers.linear(0, 0) | |
], | |
knots: [ 0, 1, 5, 6, 7] | |
}); | |
const handSequenceFrameAnimation = Animation.animate(timeDriver, handSequenceFrameSampler); | |
animationSequence0.currentFrame = handSequenceFrameAnimation; | |
const handOpacitySampler = Animation.samplers.linear(1,-3); | |
const handOpacityAnimation = Animation.animate(timeDriver, handOpacitySampler).expSmooth(100); | |
material.opacity = handOpacityAnimation; | |
// Subscribe to tap gestures on the plane | |
TouchGestures.onTap(plane).subscribe(function (gesture) { | |
// Switch materials depending on which one is currently applied to the plane | |
if(plane.materialIdentifier === material.identifier) { | |
timeDriver.start(); | |
plane.material = material; | |
} else { | |
plane.material.opacity = 100; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment