How to understand pc.CurveSet().value(time, [result])?

Hello everyone, when I was studying the use of CurveSet today, I didn’t quite understand the meaning of this passage. I would like to ask how to understand the result here, how to fill it in, and what is the use occasion?

Here is an example of a curve set:

A curve set is simply a set of several curves. On the screenshot, for example, each curve represents some values for X, Y and Z axis each. Each curve interpolates from 0 to 1 (0% to 100%).

You can create and query the interpolated value of each curve separately, e.g. ask curve X its value at 0.5, curve Y its value at 0.5 and curve Z the same - you will get X, Y and Z values at 0.5 interpolated time. Curve set is a convenience feature, that allows to add several curves into it and query them all at the same time. For example, using .value(0.5), the curve set will give you an array, where each element is a value at 0.5 time of a curve, e.g. [0.32, 1,42, 4], representing X, Y and Z values at 0.5 interpolated time.

The method .value() takes in an optional array - for example you already have an array that you want to use. You can pass it to the .value() method and pc.CurveSet will fill it for you. If you don’t pass an array, it will create a new array for you and return it with the values for each curve in its set.


Thank you for your answers. Can it be understood like this: Fill an array with the same length as the curve in the result, and the value obtained will be equal to the result?

I checked the source code of this function, and I found that no matter what value is passed in, it may not be used, but the value of the curve itself will definitely be used, which makes me very confused.

		_proto.value = function value(time, result) {
			if (result === void 0) {
				result = [];

			var length = this.curves.length;
			result.length = length;

			for (var i = 0; i < length; i++) {
				result[i] = this.curves[i].value(time);

			return result;

Ah, no, not really. I think the wording of the description could be a little better. Basically, if you give it an array, it will use it, otherwise create a new.

If you pass an array that has some values in it, those will be overwritten for the amount of curves in the set, e.g. if the set has 3 curves, the first 3 elements will be overwritten, leaving the other elements intact. I guess there could be cases where this might be useful, but I am not aware of them. Generally, you can just let it create a new array or pass an empty array to it.

Probably one case comes to mind is a minor performance optimization. If you do set queries every frame, then the curve set will create a new array every frame, which allocates new memory and will call garbage collector sooner. If you pass it an array, it will use it without allocations and you can discard it when appropriate.


I think I understand what you mean. The value of the passed-in array will never be used. After all, all values and lengths are overwritten, but the advantage of passing in is good for performance optimization.

1 Like

Thanks a lot :blush: :heart:!

1 Like

Yes, by “value” description means the attribute value you pass to .value(attribute1, attribute2), and not the value inside the array.

Ah, scratch that. After reading the description, my wording is confusing. Basically, the first sentence in the description talks about the result that will be returned from the curve set. The second sentence is about what parameters you pass to the method.

1 Like