提交 f8965d46 编写于 作者: M Mr.doob

KeyframeTrack: Removed circular dependencies.

上级 9dfca126
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
import { AnimationUtils } from './AnimationUtils.js';
import { KeyframeTrack } from './KeyframeTrack.js';
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack.js';
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack.js';
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
import { _Math } from '../math/Math.js';
/**
......@@ -32,6 +35,83 @@ function AnimationClip( name, duration, tracks ) {
}
function getTrackTypeForValueTypeName( typeName ) {
switch ( typeName.toLowerCase() ) {
case 'scalar':
case 'double':
case 'float':
case 'number':
case 'integer':
return NumberKeyframeTrack;
case 'vector':
case 'vector2':
case 'vector3':
case 'vector4':
return VectorKeyframeTrack;
case 'color':
return ColorKeyframeTrack;
case 'quaternion':
return QuaternionKeyframeTrack;
case 'bool':
case 'boolean':
return BooleanKeyframeTrack;
case 'string':
return StringKeyframeTrack;
}
throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
}
function parseKeyframeTrack( json ) {
if ( json.type === undefined ) {
throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
}
var trackType = getTrackTypeForValueTypeName( json.type );
if ( json.times === undefined ) {
var times = [], values = [];
AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
json.times = times;
json.values = values;
}
// derived classes can define a static parse method
if ( trackType.parse !== undefined ) {
return trackType.parse( json );
} else {
// by default, we assume a constructor compatible with the base
return new trackType( json.name, json.times, json.values, json.interpolation );
}
}
Object.assign( AnimationClip, {
parse: function ( json ) {
......@@ -42,7 +122,7 @@ Object.assign( AnimationClip, {
for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
}
......
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack.js';
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack.js';
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
import {
InterpolateLinear,
InterpolateSmooth,
......@@ -41,48 +35,13 @@ function KeyframeTrack( name, times, values, interpolation ) {
}
// Static methods:
// Static methods
Object.assign( KeyframeTrack, {
// Serialization (in static context, because of constructor invocation
// and automatic invocation of .toJSON):
parse: function ( json ) {
if ( json.type === undefined ) {
throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
}
var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
if ( json.times === undefined ) {
var times = [], values = [];
AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
json.times = times;
json.values = values;
}
// derived classes can define a static parse method
if ( trackType.parse !== undefined ) {
return trackType.parse( json );
} else {
// by default, we assume a constructor compatible with the base
return new trackType( json.name, json.times, json.values, json.interpolation );
}
},
toJSON: function ( track ) {
var trackType = track.constructor;
......@@ -119,48 +78,6 @@ Object.assign( KeyframeTrack, {
return json;
},
_getTrackTypeForValueTypeName: function ( typeName ) {
switch ( typeName.toLowerCase() ) {
case 'scalar':
case 'double':
case 'float':
case 'number':
case 'integer':
return NumberKeyframeTrack;
case 'vector':
case 'vector2':
case 'vector3':
case 'vector4':
return VectorKeyframeTrack;
case 'color':
return ColorKeyframeTrack;
case 'quaternion':
return QuaternionKeyframeTrack;
case 'bool':
case 'boolean':
return BooleanKeyframeTrack;
case 'string':
return StringKeyframeTrack;
}
throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
}
} );
......
......@@ -17,24 +17,12 @@ export default QUnit.module( 'Animation', () => {
} );
// STATIC STUFF
QUnit.todo( "parse", ( assert ) => {
assert.ok( false, "everything's gonna be alright" );
} );
QUnit.todo( "toJSON", ( assert ) => {
assert.ok( false, "everything's gonna be alright" );
} );
QUnit.todo( "_getTrackTypeForValueTypeName", ( assert ) => {
assert.ok( false, "everything's gonna be alright" );
} );
// PUBLIC STUFF
QUnit.todo( "TimeBufferType", ( assert ) => {
......@@ -123,4 +111,3 @@ export default QUnit.module( 'Animation', () => {
} );
} );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册