Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Convert animation to ES6. #21596

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions examples/js/animation/AnimationClipCreator.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
( function () {

var AnimationClipCreator = function () {};
class AnimationClipCreator {

AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
static CreateRotationAnimation( period, axis = 'x' ) {

var times = [ 0, period ],
values = [ 0, 360 ];
axis = axis || 'x';
var trackName = '.rotation[' + axis + ']';
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
const times = [ 0, period ],
values = [ 0, 360 ];
const trackName = '.rotation[' + axis + ']';
const track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );

};
}

static CreateScaleAxisAnimation( period, axis = 'x' ) {

const times = [ 0, period ],
values = [ 0, 1 ];
const trackName = '.scale[' + axis + ']';
const track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );

AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
}

var times = [ 0, period ],
values = [ 0, 1 ];
axis = axis || 'x';
var trackName = '.scale[' + axis + ']';
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
static CreateShakeAnimation( duration, shakeScale ) {

};
const times = [],
values = [],
tmp = new THREE.Vector3();

AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
for ( let i = 0; i < duration * 10; i ++ ) {

var times = [],
values = [],
tmp = new THREE.Vector3();
times.push( i / 10 );
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );

for ( var i = 0; i < duration * 10; i ++ ) {
}

times.push( i / 10 );
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );
const trackName = '.position';
const track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );

}

var trackName = '.position';
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreatePulsationAnimation( duration, pulseScale ) {

};
const times = [],
values = [],
tmp = new THREE.Vector3();

AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
for ( let i = 0; i < duration * 10; i ++ ) {

var times = [],
values = [],
tmp = new THREE.Vector3();
times.push( i / 10 );
const scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );

for ( var i = 0; i < duration * 10; i ++ ) {
}

times.push( i / 10 );
var scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );
const trackName = '.scale';
const track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );

}

var trackName = '.scale';
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreateVisibilityAnimation( duration ) {

};
const times = [ 0, duration / 2, duration ],
values = [ true, false, true ];
const trackName = '.visible';
const track = new THREE.BooleanKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );

AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
}

var times = [ 0, duration / 2, duration ],
values = [ true, false, true ];
var trackName = '.visible';
var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreateMaterialColorAnimation( duration, colors ) {

};
const times = [],
values = [],
timeStep = duration / colors.length;

AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
for ( let i = 0; i <= colors.length; i ++ ) {

var times = [],
values = [],
timeStep = duration / colors.length;
times.push( i * timeStep );
values.push( colors[ i % colors.length ] );

for ( var i = 0; i <= colors.length; i ++ ) {
}

times.push( i * timeStep );
values.push( colors[ i % colors.length ] );
const trackName = '.material[0].color';
const track = new THREE.ColorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );

}

var trackName = '.material[0].color';
var track = new THREE.ColorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );

};
}

THREE.AnimationClipCreator = AnimationClipCreator;

Expand Down
Loading