Skip to content

Commit

Permalink
Merge ce5cf33 into 8f7ff98
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed May 31, 2019
2 parents 8f7ff98 + ce5cf33 commit 172f278
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
57 changes: 27 additions & 30 deletions examples/core/animation/app.js
Expand Up @@ -5,26 +5,12 @@ import {Timeline, KeyFrames} from '@luma.gl/addons';
import {Matrix4, radians} from 'math.gl';

const INFO_HTML = `
Animations based on multiple hierarchical timelines.
Key frame animation based on multiple hierarchical timelines.
<button id="play">Play</button>
<button id="pause">Pause</button><BR>
Time: <input type="range" id="time" min="0" max="30000" step="1"><BR>
`;

const controls = document.createElement('div');
controls.innerHTML = `
<button id="play">Play</button>
<button id="pause">Pause</button><BR>
Time: <input type="range" id="time" min="0" max="30000" step="1"><BR>
`;
controls.style.position = 'absolute';
controls.style.top = '10px';
controls.style.left = '10px';
controls.style.background = 'white';
controls.style.padding = '0.5em';
document.body.appendChild(controls);

const playButton = document.getElementById('play');
const pauseButton = document.getElementById('pause');
const timeSlider = document.getElementById('time');

const vs = `\
attribute vec3 positions;
attribute vec3 normals;
Expand Down Expand Up @@ -74,17 +60,23 @@ export default class AppAnimationLoop extends AnimationLoop {
depthFunc: gl.LEQUAL
});

playButton.addEventListener('click', () => {
this.timeline.play();
});
const playButton = document.getElementById('play');
const pauseButton = document.getElementById('pause');
const timeSlider = document.getElementById('time');

pauseButton.addEventListener('click', () => {
this.timeline.pause();
});
if (playButton) {
playButton.addEventListener('click', () => {
this.timeline.play();
});

timeSlider.addEventListener('input', event => {
this.timeline.setTime(parseFloat(event.target.value));
});
pauseButton.addEventListener('click', () => {
this.timeline.pause();
});

timeSlider.addEventListener('input', event => {
this.timeline.setTime(parseFloat(event.target.value));
});
}

const translations = [[2, -2, 0], [2, 2, 0], [-2, 2, 0], [-2, -2, 0]];

Expand Down Expand Up @@ -167,11 +159,16 @@ export default class AppAnimationLoop extends AnimationLoop {
})
};
}

return {timeSlider};
}

onRender(animationProps) {
const {gl} = animationProps;
timeSlider.value = this.timeline.getTime();
const {gl, timeSlider} = animationProps;

if (timeSlider) {
timeSlider.value = this.timeline.getTime();
}

const modelMatrix = new Matrix4();

Expand Down Expand Up @@ -200,7 +197,7 @@ export default class AppAnimationLoop extends AnimationLoop {

onFinalize({gl}) {
for (let i = 0; i < 4; ++i) {
this.cube[i].model.delete();
this.cubes[i].model.delete();
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion website/contents/demos.js
@@ -1,4 +1,4 @@
import {setContextDefaults} from 'luma.gl';
import {setContextDefaults} from '@luma.gl/core';
setContextDefaults({webgl2: true});

export {default as InstancingDemo} from '../../examples/core/instancing/app.js';
Expand All @@ -13,6 +13,7 @@ export {default as TransformDemo} from '../../examples/core/transform/app.js';
export {default as GLTFDemo} from '../../examples/core/gltf/app';
export {default as QuasicrystalsDemo} from '../../examples/core/quasicrystals/app';
export {default as Texture3DDemo} from '../../examples/core/texture-3d/app';
export {default as AnimationDemo} from '../../examples/core/animation/app';

export {default as Lesson01} from '../../examples/lessons/01/app.js';
export {default as Lesson02} from '../../examples/lessons/02/app.js';
Expand Down
7 changes: 7 additions & 0 deletions website/contents/pages.js
Expand Up @@ -51,6 +51,13 @@ export const EXAMPLE_PAGES = [
code: `${GITHUB_TREE}/examples/core/shadowmap`
}
},
{
name: 'Animation',
content: {
demo: 'AnimationDemo',
code: `${GITHUB_TREE}/examples/core/animation`
}
},
{
name: 'Transform Feedback (WebGL2)',
content: {
Expand Down
Binary file added website/src/static/images/example-animation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions website/src/static/markdown/examples.md
Expand Up @@ -43,6 +43,13 @@
</a>
</div>
</div>
<div class="thumb">
<div class="bg-black" data-title="Animation">
<a href="#/examples/core-examples/animation">
<img src="images/example-animation.png" />
</a>
</div>
</div>
<div class="thumb">
<div class="bg-black" data-title="Transform Feedback">
<a href="#/examples/core-examples/transform-feedback-webgl-2">
Expand Down

0 comments on commit 172f278

Please sign in to comment.