[SOLVED] Default Value for Curve Script Attribute

I’d like to set a default value for a curve script attribute. I know I need to use the default: property, but I don’t know what I need to put for the default: value, because I don’t know how to programmatically define a curve. :slight_smile: I’ve looked around a bit in the API and don’t see any code examples on the subject.

Here is example how to set default values for curve attributes, it best should be documented.
As you can see, keys are array of pairs of numbers, where it goes: [ time, value, time, value, ... ], and you can have time to be within 0.0 .. 1.0 range, where value can be any float. And you can have as many keys as you want, but ensure they are in sorted order by time.
For curvesets (color or position in this example), you need to provide array of arrays for each curve as per example below.


Test.attributes.add('single', { type: 'curve', default: {
    keys: [ 0, 0.5, 0.5, 1, 1, 0 ]
}});

Test.attributes.add('color', { type: 'curve', color: 'rgb', default: {
    keys: [
        [ 0, 0.5, 0.5, 1, 1, 0 ],
        [ 0, 0, 0.5, 0.5, 1, 1 ],
        [ 0, 1, 0.5, 0, 1, 0.5 ]
    ]
}});

Test.attributes.add('position', { type: 'curve', curves: 'xyz', default: {
    keys: [
        [ 0, 5, 1, 0 ],
        [ 0, 0, 1, 10 ],
        [ 0, 10, 1, 5 ]
    ]
}});
4 Likes

Perfect, thanks for showing!

Is there a way to set the default interpolation type?

Yep, you can add type.

Test.attributes.add('color', { type: 'curve', color: 'rgb', default: {
    keys: [
        [ 0, 0.5, 0.5, 1, 1, 0 ],
        [ 0, 0, 0.5, 0.5, 1, 1 ],
        [ 0, 1, 0.5, 0, 1, 0.5 ]
    ],
   type: pc.CURVE_LINEAR
}});

1 Like

neat, thanks!