123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- this.animationTime_set = function (value) {
- if (this.animationStartTime == null) {
- this.animationStartTime = 0;
- }
- if (this.animationStopTime == null) {
- this.animationStopTime = this.animationDuration;
- }
-
- var duration = this.animationStopTime - this.animationStartTime,
- rate = this.animationRate;
-
- value = Math.min(Math.max(this.animationStartTime, value), this.animationStopTime);
-
-
- if (this.animationStartSIM == null) {
- this.animationPauseSIM = 0;
- }
-
- this.animationStartSIM =
- (this.animationPauseSIM != null ? this.animationPauseSIM : this.time) -
- (rate >= 0 ? value - this.animationStartTime : value - duration) / rate;
- this.animationStopSIM =
- this.animationStartSIM +
- (rate >= 0 ? duration : -duration) / rate;
-
- if (value !== this.animationTimeUpdated) {
- this.animationTimeUpdated = value;
- this.animationUpdate(value, this.animationDuration);
- this.animationTimeChanged(value);
- }
- }
- this.animationTime_get = function () {
-
- var startTime = this.animationStartTime;
- var stopTime = this.animationStopTime;
- var rate = this.animationRate;
- var animationPauseSIM = this.animationPauseSIM;
- var animationStartSIM = this.animationStartSIM;
- var time = this.time;
-
- var value = (
- (animationPauseSIM != null ? animationPauseSIM : time) -
- (animationStartSIM != null ? animationStartSIM : time)
- ) * rate + (rate >= 0 ? startTime : stopTime);
-
- value = Math.min(Math.max(startTime, value), stopTime);
-
- if (value !== this.animationTimeUpdated) {
- this.animationTimeUpdated = value;
- this.animationUpdate(value, this.animationDuration);
- this.animationTimeChanged(value);
- }
- return value;
- }
- this.animationDuration_set = function (value) {
- var duration = value, rate = this.animationRate;
- this.animationDuration = duration;
- this.animationDurationSIM = (rate >= 0 ? duration : -duration) / rate;
- }
- this.animationRate_set = function (value) {
- var duration = this.animationDuration, rate = value;
- this.animationRate = rate;
- this.animationDurationSIM = (rate >= 0 ? duration : -duration) / rate;
- }
- this.animationPlaying_set = function (value) {
- if (this.animationStartTime == null) {
- this.animationStartTime = 0;
- }
- if (this.animationStopTime == null) {
- this.animationStopTime = this.animationDuration;
- }
- if (this.animationStartSIM != null && this.animationPauseSIM == null) {
- if (!value) {
-
- this.animationPauseSIM = this.time;
-
- if (this.time == this.animationStopSIM) {
- this.animationStopped();
- }
- }
- } else {
- if (value) {
-
- var duration = this.animationStopTime - this.animationStartTime,
- rate = this.animationRate;
-
- if (this.animationPauseSIM == this.animationStopSIM) {
- this.animationPauseSIM = this.animationStartSIM;
- }
-
- this.animationStartSIM =
- (this.animationStartSIM != null ? this.animationStartSIM : this.time) -
- (this.animationPauseSIM != null ? this.animationPauseSIM : this.time) +
- this.time;
- this.animationStopSIM =
- this.animationStartSIM +
- (rate >= 0 ? duration : -duration) / rate;
- this.animationPauseSIM = null;
-
- if (this.time == this.animationStartSIM) {
- this.animationStarted();
- }
-
- this.logger.debug("scheduling animationTick");
- this.animationTick();
- }
- }
- }
- this.animationPlaying_get = function () {
- return this.animationStartSIM != null && this.animationPauseSIM == null;
- }
- this.animationStartTime_set = function (value) {
- this.animationStartTime = value ? Math.min(Math.max(0, value), this.animationDuration) : value;
- }
- this.animationStopTime_set = function (value) {
- this.animationStopTime = value ? Math.min(Math.max(0, value), this.animationDuration) : value;
- }
- this.animationStartFrame_set = function (value) {
- this.animationStartTime = value / this.animationFPS
- }
- this.animationStartFrame_get = function () {
- return Math.floor(this.animationStartTime * this.animationFPS)
- }
- this.animationStopFrame_set = function (value) {
- this.animationStopTime = value / this.animationFPS
- }
- this.animationStopFrame_get = function () {
- return Math.floor(this.animationStopTime * this.animationFPS)
- }
- this.animationFrames_set = function (value) {
- this.animationDuration = value / this.animationFPS
- }
- this.animationFrames_get = function () {
- return Math.ceil(this.animationFPS * this.animationDuration)
- }
- this.animationFrame_set = function (value) {
- if (this.animationFPS) {
- this.animationTime = value / this.animationFPS;
- }
- }
- this.animationFrame_get = function () {
- if (this.animationFPS) {
- return Math.floor(this.animationTime * this.animationFPS);
- }
- }
- this.animationPlay = function (startTime, stopTime) {
- if (!isNaN(stopTime)) {
- this.animationStopTime = stopTime;
- }
- if (!isNaN(startTime)) {
- this.animationStartTime = startTime;
- }
- this.animationPlaying = true;
- }
- this.animationPause = function () {
- this.animationPlaying = false;
- }
- this.animationResume = function () {
- this.animationPlaying = true;
- }
- this.animationStop = function () {
- this.animationPlaying = false;
- this.animationTime = 0;
- }
- this.animationTick = function () {
- if (this.animationPlaying) {
-
-
- this.animationTime;
-
- if (this.time === this.animationStopSIM) {
- if (this.animationLoop) {
- this.animationLooped();
- this.animationTime = this.animationRate >= 0 ?
- this.animationStartTime : this.animationStopTime;
- } else {
- this.animationPlaying = false;
- }
- }
-
- if (this.animationPlaying) {
- if (this.animationStopSIM - this.time > 1 / this.animationTPS) {
- this.in(1 / this.animationTPS).animationTick();
- } else {
-
-
-
-
-
-
-
- if (this.animationStopSIM > 0) {
- this.at(this.animationStopSIM).animationTick();
- } else {
- this.animationPlaying = false;
- }
- }
- } else {
- this.logger.debug("canceling animationTick");
- }
- }
- }
- this.animationUpdate = function (time, duration) {
-
- }
- this.initialize = function () {
-
-
- var positions = this.find("./element(*,'proxy/animation/position.vwf')");
-
-
-
-
-
-
-
-
- var leftTime, leftIndex;
- var rightTime, rightIndex = -Infinity;
- if (positions.length > 0) {
- positions.sort(function (a, b) {
- return a.sequence - b.sequence;
- });
- if (positions[0].animationTime === null) {
- positions[0].animationTime = 0;
- }
- if (positions[positions.length - 1].animationTime === null) {
- positions[positions.length - 1].animationTime = this.animationDuration;
- }
- positions.forEach(function (position, index) {
- if (position.animationTime !== null) {
- leftTime = position.animationTime;
- leftIndex = index;
- } else {
- if (index > rightIndex) {
- for (rightIndex = index + 1; rightIndex < positions.length; rightIndex++) {
- if ((rightTime = positions[rightIndex].animationTime) !== null) {
- break;
- }
- }
- }
- position.animationTime = leftTime + (rightTime - leftTime) *
- (index - leftIndex) / (rightIndex - leftIndex);
- }
- }, this);
- }
- }
|