import oktween from '../../util/vendor/oktween' import { choice } from '../../util' import { faces, names } from './faces' import * as markers from './markers' import * as mesh from './mesh' export function init() { const name = choice(names) const face = faces[name] markers.build(face) // mesh.load(name) startAnimation() } export function startAnimation() { const name = choice(names) const face = faces[name] mesh.remove() mesh.load(name).then(geometry => { let meshes markers.swap(face) .then({ obj: {}, duration: 0, finished: () => { meshes = mesh.createFaceMeshes(geometry) meshes.wireframe.position.z -= 0.001 } }) .then({ from: { n: 0 }, to: { n: 1 }, duration: 500, easing: oktween.easing.quad_in_out, update: (obj) => { meshes.blank.material.opacity = obj.n }, }) .then({ from: { n: 0 }, to: { n: 1 }, delay: 500, duration: 500, easing: oktween.easing.quad_in, update: (obj) => { meshes.blank.material.opacity = 1 - obj.n meshes.solid.material.opacity = obj.n }, finished: () => { mesh.removeMesh('blank') } }) .then({ from: { n: 0, lines: 1, cubes: 1, }, to: { n: 1, lines: 0, cubes: 0.5 }, delay: 500, duration: 1000, easing: oktween.easing.quad_in, update: (obj) => { meshes.solid.material.opacity = 1 - obj.n meshes.wireframe.material.opacity = obj.n markers.fadePointsTo(obj.cubes) markers.fadeLinesTo(obj.lines) }, finished: () => { mesh.removeMesh('solid') } }) .then({ from: { n: 1, lines: 0, cubes: 0 }, to: { n: 0, lines: 1, cubes: 1 }, delay: 5000, duration: 500, easing: oktween.easing.quad_out, update: (obj) => { meshes.wireframe.material.opacity = obj.n markers.fadePointsTo(obj.cubes) markers.fadeLinesTo(obj.lines) }, }) .then({ obj: {}, duration: 0, finished: () => { startAnimation() } }) }) } // export function update() { // markers.update() // }