@@ -19,9 +19,14 @@ class CurveSet {
1919 /**
2020 * Creates a new CurveSet instance.
2121 *
22- * @param {Array<number[]> } curveKeys - An array of arrays of keys (pairs of numbers with the
23- * time first and value second).
22+ * @param {...* } args - Variable arguments with several possible formats:
23+ * - No arguments: Creates a CurveSet with a single default curve.
24+ * - Single number argument: Creates a CurveSet with the specified number of default curves.
25+ * - Single array argument: An array of arrays, where each sub-array contains keys (pairs of
26+ * numbers with the time first and value second).
27+ * - Multiple arguments: Each argument becomes a separate curve.
2428 * @example
29+ * // Create from an array of arrays of keys
2530 * const curveSet = new pc.CurveSet([
2631 * [
2732 * 0, 0, // At 0 time, value of 0
@@ -37,24 +42,27 @@ class CurveSet {
3742 * ]
3843 * ]);
3944 */
40- constructor ( ) {
41- if ( arguments . length > 1 ) {
42- for ( let i = 0 ; i < arguments . length ; i ++ ) {
43- this . curves . push ( new Curve ( arguments [ i ] ) ) ;
45+ constructor ( ...args ) {
46+ if ( args . length > 1 ) {
47+ // Multiple arguments: each becomes a curve
48+ for ( let i = 0 ; i < args . length ; i ++ ) {
49+ this . curves . push ( new Curve ( args [ i ] ) ) ;
4450 }
51+ } else if ( args . length === 0 ) {
52+ // No arguments: create a single default curve
53+ this . curves . push ( new Curve ( ) ) ;
4554 } else {
46- if ( arguments . length === 0 ) {
47- this . curves . push ( new Curve ( ) ) ;
55+ // Single argument
56+ const arg = args [ 0 ] ;
57+ if ( typeof arg === 'number' ) {
58+ // Number: create specified number of default curves
59+ for ( let i = 0 ; i < arg ; i ++ ) {
60+ this . curves . push ( new Curve ( ) ) ;
61+ }
4862 } else {
49- const arg = arguments [ 0 ] ;
50- if ( typeof arg === 'number' ) {
51- for ( let i = 0 ; i < arg ; i ++ ) {
52- this . curves . push ( new Curve ( ) ) ;
53- }
54- } else {
55- for ( let i = 0 ; i < arg . length ; i ++ ) {
56- this . curves . push ( new Curve ( arg [ i ] ) ) ;
57- }
63+ // Array: each element becomes a curve
64+ for ( let i = 0 ; i < arg . length ; i ++ ) {
65+ this . curves . push ( new Curve ( arg [ i ] ) ) ;
5866 }
5967 }
6068 }
0 commit comments