Skip to content

Commit f8965d4

Browse files
committed
KeyframeTrack: Removed circular dependencies.
1 parent 9dfca12 commit f8965d4

File tree

3 files changed

+85
-101
lines changed

3 files changed

+85
-101
lines changed

src/animation/AnimationClip.js

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
2-
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
3-
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
41
import { AnimationUtils } from './AnimationUtils.js';
52
import { KeyframeTrack } from './KeyframeTrack.js';
3+
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack.js';
4+
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack.js';
5+
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
6+
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
7+
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
8+
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
69
import { _Math } from '../math/Math.js';
710

811
/**
@@ -32,6 +35,83 @@ function AnimationClip( name, duration, tracks ) {
3235

3336
}
3437

38+
function getTrackTypeForValueTypeName( typeName ) {
39+
40+
switch ( typeName.toLowerCase() ) {
41+
42+
case 'scalar':
43+
case 'double':
44+
case 'float':
45+
case 'number':
46+
case 'integer':
47+
48+
return NumberKeyframeTrack;
49+
50+
case 'vector':
51+
case 'vector2':
52+
case 'vector3':
53+
case 'vector4':
54+
55+
return VectorKeyframeTrack;
56+
57+
case 'color':
58+
59+
return ColorKeyframeTrack;
60+
61+
case 'quaternion':
62+
63+
return QuaternionKeyframeTrack;
64+
65+
case 'bool':
66+
case 'boolean':
67+
68+
return BooleanKeyframeTrack;
69+
70+
case 'string':
71+
72+
return StringKeyframeTrack;
73+
74+
}
75+
76+
throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
77+
78+
}
79+
80+
function parseKeyframeTrack( json ) {
81+
82+
if ( json.type === undefined ) {
83+
84+
throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
85+
86+
}
87+
88+
var trackType = getTrackTypeForValueTypeName( json.type );
89+
90+
if ( json.times === undefined ) {
91+
92+
var times = [], values = [];
93+
94+
AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
95+
96+
json.times = times;
97+
json.values = values;
98+
99+
}
100+
101+
// derived classes can define a static parse method
102+
if ( trackType.parse !== undefined ) {
103+
104+
return trackType.parse( json );
105+
106+
} else {
107+
108+
// by default, we assume a constructor compatible with the base
109+
return new trackType( json.name, json.times, json.values, json.interpolation );
110+
111+
}
112+
113+
}
114+
35115
Object.assign( AnimationClip, {
36116

37117
parse: function ( json ) {
@@ -42,7 +122,7 @@ Object.assign( AnimationClip, {
42122

43123
for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
44124

45-
tracks.push( KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
125+
tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
46126

47127
}
48128

src/animation/KeyframeTrack.js

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
2-
import { BooleanKeyframeTrack } from './tracks/BooleanKeyframeTrack.js';
3-
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
4-
import { ColorKeyframeTrack } from './tracks/ColorKeyframeTrack.js';
5-
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
6-
import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
71
import {
82
InterpolateLinear,
93
InterpolateSmooth,
@@ -41,48 +35,13 @@ function KeyframeTrack( name, times, values, interpolation ) {
4135

4236
}
4337

44-
// Static methods:
38+
// Static methods
4539

4640
Object.assign( KeyframeTrack, {
4741

4842
// Serialization (in static context, because of constructor invocation
4943
// and automatic invocation of .toJSON):
5044

51-
parse: function ( json ) {
52-
53-
if ( json.type === undefined ) {
54-
55-
throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
56-
57-
}
58-
59-
var trackType = KeyframeTrack._getTrackTypeForValueTypeName( json.type );
60-
61-
if ( json.times === undefined ) {
62-
63-
var times = [], values = [];
64-
65-
AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
66-
67-
json.times = times;
68-
json.values = values;
69-
70-
}
71-
72-
// derived classes can define a static parse method
73-
if ( trackType.parse !== undefined ) {
74-
75-
return trackType.parse( json );
76-
77-
} else {
78-
79-
// by default, we assume a constructor compatible with the base
80-
return new trackType( json.name, json.times, json.values, json.interpolation );
81-
82-
}
83-
84-
},
85-
8645
toJSON: function ( track ) {
8746

8847
var trackType = track.constructor;
@@ -119,48 +78,6 @@ Object.assign( KeyframeTrack, {
11978

12079
return json;
12180

122-
},
123-
124-
_getTrackTypeForValueTypeName: function ( typeName ) {
125-
126-
switch ( typeName.toLowerCase() ) {
127-
128-
case 'scalar':
129-
case 'double':
130-
case 'float':
131-
case 'number':
132-
case 'integer':
133-
134-
return NumberKeyframeTrack;
135-
136-
case 'vector':
137-
case 'vector2':
138-
case 'vector3':
139-
case 'vector4':
140-
141-
return VectorKeyframeTrack;
142-
143-
case 'color':
144-
145-
return ColorKeyframeTrack;
146-
147-
case 'quaternion':
148-
149-
return QuaternionKeyframeTrack;
150-
151-
case 'bool':
152-
case 'boolean':
153-
154-
return BooleanKeyframeTrack;
155-
156-
case 'string':
157-
158-
return StringKeyframeTrack;
159-
160-
}
161-
162-
throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
163-
16481
}
16582

16683
} );

test/unit/src/animation/KeyframeTrack.tests.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,12 @@ export default QUnit.module( 'Animation', () => {
1717
} );
1818

1919
// STATIC STUFF
20-
QUnit.todo( "parse", ( assert ) => {
21-
22-
assert.ok( false, "everything's gonna be alright" );
23-
24-
} );
25-
2620
QUnit.todo( "toJSON", ( assert ) => {
2721

2822
assert.ok( false, "everything's gonna be alright" );
2923

3024
} );
3125

32-
QUnit.todo( "_getTrackTypeForValueTypeName", ( assert ) => {
33-
34-
assert.ok( false, "everything's gonna be alright" );
35-
36-
} );
37-
3826
// PUBLIC STUFF
3927
QUnit.todo( "TimeBufferType", ( assert ) => {
4028

@@ -123,4 +111,3 @@ export default QUnit.module( 'Animation', () => {
123111
} );
124112

125113
} );
126-

0 commit comments

Comments
 (0)