123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- ---
- properties:
-
-
-
-
-
-
- animationTime:
- set: |
- if(this.animationStartTime == null) {
- this.animationStartTime = 0;
- }
- if(this.animationStopTime == null) {
- this.animationStopTime = this.animationDuration;
- }
- // Save copies to avoid repeated reads.
- var duration = this.animationStopTime - this.animationStartTime,
- rate = this.animationRate;
- // Range limit the incoming value.
- value = Math.min( Math.max( this.animationStartTime, value ), this.animationStopTime );
- // Keep paused if updating start/pause from null/null. Use t=0 instead of `this.time` so that
- // setting `node.animationTime` during initialization is consistent across multiple clients.
- if ( this.animationStart$ == null ) {
- this.animationPause$ = 0;
- }
- // Calculate the start and stop times that makes the new time work.
- this.animationStart$ =
- ( this.animationPause$ != null ? this.animationPause$ : this.time ) -
- ( rate >= 0 ? value - this.animationStartTime : value - duration ) / rate;
- this.animationStop$ =
- this.animationStart$ +
- ( rate >= 0 ? duration : -duration ) / rate;
- // Update the node and fire the changed event.
- if ( value !== this.animationTimeUpdated ) {
- this.animationTimeUpdated = value;
- this.animationUpdate( value, this.animationDuration );
- this.animationTimeChanged( value );
- } //@ sourceURL=animation.animationTime.set.vwf
- get: |
- // Save copies to avoid repeated reads.
- var startTime = this.animationStartTime;
- var stopTime = this.animationStopTime;
- var rate = this.animationRate;
- var animationPause$ = this.animationPause$;
- var animationStart$ = this.animationStart$;
- var time = this.time;
- // Calculate the time from the start and current/pause times.
- var value = (
- ( animationPause$ != null ? animationPause$ : time ) -
- ( animationStart$ != null ? animationStart$ : time )
- ) * rate + ( rate >= 0 ? startTime : stopTime );
- // Range limit the value.
- value = Math.min( Math.max( startTime, value ), stopTime );
- // If changed since last seen, update and fire the changed event.
- if ( value !== this.animationTimeUpdated ) {
- this.animationTimeUpdated = value;
- this.animationUpdate( value, this.animationDuration );
- this.animationTimeChanged( value );
- }
- return value; //@ sourceURL=animation.animationTime.get.vwf
-
-
-
-
-
-
- animationDuration:
- set: |
- var duration = value, rate = this.animationRate;
- this.animationDuration = duration;
- this.animationDuration$ = ( rate >= 0 ? duration : -duration ) / rate;
- value: 1
-
-
-
-
- animationRate:
- set: |
- var duration = this.animationDuration, rate = value;
- this.animationRate = rate;
- this.animationDuration$ = ( rate >= 0 ? duration : -duration ) / rate;
- value: 1
-
- animationLoop: false
-
- animationPlaying:
- set: |
- if(this.animationStartTime == null) {
- this.animationStartTime = 0;
- }
- if(this.animationStopTime == null) {
- this.animationStopTime = this.animationDuration;
- }
- if ( this.animationStart$ != null && this.animationPause$ == null ) {
- if ( ! value ) {
- // Mark as paused at the current time.
- this.animationPause$ = this.time;
- // Send the `animationStopped` event if stopping at the end.
- if ( this.time == this.animationStop$ ) {
- this.animationStopped();
- }
- }
- } else {
- if ( value ) {
- // Save copies to avoid repeated reads.
- var duration = this.animationStopTime - this.animationStartTime,
- rate = this.animationRate;
- // Start from the beginning if resuming from the end.
- if ( this.animationPause$ == this.animationStop$ ) {
- this.animationPause$ = this.animationStart$;
- }
- // Recalculate the start and stop times to keep paused time unchanged, then resume.
- this.animationStart$ =
- ( this.animationStart$ != null ? this.animationStart$ : this.time ) -
- ( this.animationPause$ != null ? this.animationPause$ : this.time ) +
- this.time;
- this.animationStop$ =
- this.animationStart$ +
- ( rate >= 0 ? duration : -duration ) / rate;
- this.animationPause$ = null;
- // Send the `animationStarted` event if starting from the beginning.
- if ( this.time == this.animationStart$ ) {
- this.animationStarted();
- }
- // Start the animation worker.
- this.logger.debug( "scheduling animationTick" );
- this.animationTick();
- }
- } //@ sourceURL=animation.animationPlaying.set.vwf
- get: |
- return this.animationStart$ != null && this.animationPause$ == null;
-
-
-
-
-
-
- animationTimeUpdated: null
-
-
-
-
-
-
- animationStart$: null
-
-
-
-
-
-
- animationPause$: null
-
-
-
-
- animationStop$: null
-
-
-
- animationDuration$: null
-
-
-
-
- animationStartTime:
- set: |
- this.animationStartTime = value ? Math.min( Math.max( 0, value ), this.animationDuration ) : value;
- value: null
-
-
-
-
- animationStopTime:
- set: |
- this.animationStopTime = value ? Math.min( Math.max( 0, value ), this.animationDuration ) : value;
- value: null
-
-
- animationStartFrame:
- set: |
- this.animationStartTime = value / this.animationFPS;
- get: |
- return Math.floor(this.animationStartTime * this.animationFPS);
-
-
- animationStopFrame:
- set: |
- this.animationStopTime = value / this.animationFPS;
- get: |
- return Math.floor(this.animationStopTime * this.animationFPS);
-
- animationFPS: 30
-
- animationFrames:
- set: |
- this.animationDuration = value / this.animationFPS;
- get: |
- return Math.ceil(this.animationFPS * this.animationDuration);
-
- animationFrame:
- set: |
- if(this.animationFPS) {
- this.animationTime = value / this.animationFPS;
- }
- get: |
- if(this.animationFPS) {
- return Math.floor(this.animationTime * this.animationFPS);
- }
-
- animationTPS: 60
- methods:
-
- animationPlay:
- parameters:
- - startTime
- - stopTime
- body: |
- if(!isNaN(stopTime)) {
- this.animationStopTime = stopTime;
- }
- if(!isNaN(startTime)) {
- this.animationStartTime = startTime;
- }
- this.animationPlaying = true;
-
- animationPause: |
- this.animationPlaying = false;
-
- animationResume: |
- this.animationPlaying = true;
-
- animationStop: |
- this.animationPlaying = false;
- this.animationTime = 0;
-
-
-
-
- animationTick: |
- if ( this.animationPlaying ) {
- // Read the time to recognize the current time and update.
- // TODO: move side effects out of the getter!!! (says Kevin)
- this.animationTime;
- // Loop or stop after reaching the end.
- if ( this.time === this.animationStop$ ) {
- if ( this.animationLoop ) {
- this.animationLooped();
- this.animationTime = this.animationRate >= 0 ?
- this.animationStartTime : this.animationStopTime;
- } else {
- this.animationPlaying = false;
- }
- }
- // Schedule the next tick if still playing.
- if ( this.animationPlaying ) {
- if ( this.animationStop$ - this.time > 1 / this.animationTPS ) {
- this.in( 1 / this.animationTPS ).animationTick(); // next interval
- } else {
- // TODO: When animationStop$ is 0 (usually when a model does not actually have an
- // animation on it), we schedule a method call for a time in the past (at time 0).
- // That immediately calls animationTick again, but this.time does not equal
- // animationStop$ as we would expect. So, it doesn't stop the animation and we get
- // caught in an infinite loop.
- // Ideally we should catch the case where animationStop$ is 0 before this point.
- // But for now, we catch it here.
- if ( this.animationStop$ > 0 ) {
- this.at( this.animationStop$ ).animationTick(); // exactly at end
- } else {
- this.animationPlaying = false;
- }
- }
- } else {
- this.logger.debug( "canceling animationTick" );
- }
- } //@ sourceURL=animation.animationTick.vwf
-
-
-
-
-
-
-
-
-
-
-
-
- animationUpdate:
- parameters:
- - time
- - duration
- events:
-
- animationStarted:
-
- animationStopped:
-
- animationLooped:
-
-
-
-
-
-
-
-
- animationTimeChanged:
- parameters:
- - time
- scripts:
- - |
- this.initialize = function() {
- // Locate child nodes that extend or implement "http://vwf.example.com/animation/position.vwf"
- // to identify themselves as animation key positions.
- var positions = this.find( "./element(*,'http://vwf.example.com/animation/position.vwf')" );
- // Fill in missing `animationTime` properties, distributing evenly between the left and right
- // positions that define `animationTime`.
- // 1: [ - ] => [ 0 ]
- // 1: [ 0, - ] => [ 0, 1 ]
- // 1: [ -, 1 ] => [ 0, 1 ]
- // 1: [ 0, -, - ] => [ 0, 1/2, 1 ]
- // 1: [ -, -, 1 ] => [ 0, 1/2, 1 ]
- // 1: [ 0, - , -, 1 ] => [ 0, 1/3 , 2/3, 1 ]
- 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 = /* assignment! */ positions[rightIndex].animationTime ) !== null ) {
- break;
- }
- }
- }
- position.animationTime = leftTime + ( rightTime - leftTime ) *
- ( index - leftIndex ) / ( rightIndex - leftIndex );
- }
- }, this );
- }
- } //@ sourceURL=http://vwf.example.com/animation.vwf/scripts~initialize
|