Skip to content

Commit

Permalink
Merge pull request #298 from iTowns/CONTROL
Browse files Browse the repository at this point in the history
Move controls function to globeControls
  • Loading branch information
peppsac authored May 18, 2017
2 parents 96ec8ae + 2a5e295 commit 2166f0d
Show file tree
Hide file tree
Showing 8 changed files with 441 additions and 493 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/Main.js",
"scripts": {
"lint": "eslint \"src/**/*.js\" \"test/**/*.js\" \"examples/**/*.js\"",
"doc": "jsdoc src/Core/Scheduler/Interfaces/ApiInterface/*",
"doc": "jsdoc src/Core/Scheduler/Interfaces/ApiInterface/* src/Renderer/ThreeExtended/GlobeControls.js",
"doclint": "npm run doc -- -t templates/silent",
"test": "npm run lint && npm run build && npm run doclint",
"build": "webpack -p",
Expand Down
31 changes: 21 additions & 10 deletions src/Core/AnimationPlayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as THREE from 'three';

const FRAMERATE = 60;
const FRAME_DURATION = 1000 / FRAMERATE;
// if is true console.log are enabled to sniff animation'state
Expand Down Expand Up @@ -54,6 +56,16 @@ const resetTimer = function resetTimer(player) {
// finish animation and re-init parameter
const finishAnimation = function finishAnimation(player) {
resetTimer(player);
if (player.isEnded()) {
player.dispatchEvent({
type: 'animation-ended',
animation: player.animation,
});
}
player.dispatchEvent({
type: 'animation-stopped',
animation: player.animation,
});
player.animation = null;
if (player.resolve) {
player.resolve();
Expand All @@ -67,10 +79,6 @@ const setPlayerState = function setPlayerState(player, state) {
_DEBUG(debugMsg[state], player.animation);
};

const frameEvent = new CustomEvent('frameAnimation');
const stopEvent = new CustomEvent('stopAnimation');
const endEvent = new CustomEvent('endAnimation');

/**
* AnimationPlayer
* It can play, pause or stop Animation or AnimationExpression (See below).
Expand All @@ -80,9 +88,9 @@ const endEvent = new CustomEvent('endAnimation');
* - when Animation is stopped
* - when Animation is ending
*/
class AnimationPlayer {
constructor(dom) {
this.dom = dom;
class AnimationPlayer extends THREE.EventDispatcher {
constructor() {
super();
this.id = null;
this.keyframe = 0;
this.animation = null;
Expand Down Expand Up @@ -115,6 +123,9 @@ class AnimationPlayer {
*/
play(animation) {
this.animation = animation;
this.dispatchEvent({
type: 'animation-started',
animation });
setPlayerState(this, PLAYER_STATE.PLAY);
resetTimer(this);
this.id = setInterval(this.frame.bind(this), FRAME_DURATION);
Expand Down Expand Up @@ -145,7 +156,6 @@ class AnimationPlayer {
stop() {
setPlayerState(this, PLAYER_STATE.STOP);
finishAnimation(this);
this.dom.dispatchEvent(stopEvent);
// needed to return promise to wait sync
return Promise.resolve();
}
Expand All @@ -159,12 +169,13 @@ class AnimationPlayer {
this.animation.animate(this.keyframe);
}
this.keyframe++;
this.dom.dispatchEvent(frameEvent);
this.dispatchEvent({
type: 'animation-frame',
});
}
else {
setPlayerState(this, PLAYER_STATE.END);
finishAnimation(this);
this.dom.dispatchEvent(endEvent);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Prefab/GlobeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function GlobeView(viewerDiv, coordCarto) {
this.camera.camera3D,
positionTargetCamera.as('EPSG:4978').xyz(),
engine.renderer.domElement,
viewerDiv,
engine,
size,
'EPSG:4978',
Expand Down Expand Up @@ -144,6 +145,10 @@ function GlobeView(viewerDiv, coordCarto) {
this.mainLoop.addEventListener('command-queue-empty', () => {
viewerDiv.dispatchEvent(new CustomEvent('globe-built'));
});

window.addEventListener('resize', () => {
this.controls.updateCamera(this.camera, this.viewerDiv.clientWidth, this.viewerDiv.clientHeight);
}, false);
}

GlobeView.prototype = Object.create(View.prototype);
Expand Down
Loading

0 comments on commit 2166f0d

Please sign in to comment.