Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Edit control points properties from script
#1
Hi!




I'm trying to create a rope from script that can be edited in runtime. Therefore, I need to add and edit control points in a blueprint in runtime. I found how to add control points with AddControlPoint(), but the only way I found to edit properties of a given control point in runtime, is by deleting all control points with this :



Code:
int nbrControlPoint = _blueprint.path.ControlPointCount - 1;
for (int i = nbrControlPoint; i >= 0; i--)
{
    _blueprint.path.RemoveControlPoint(i);
}



And re-add control points with the new properties. However, I think this method is neither efficient, nor clean.




Is there another way to do it ?
Reply
#2
(10-12-2021, 04:39 PM)lufydad Wrote: And re-add control points with the new properties. However, I think this method is neither efficient, nor clean.

Is there another way to do it ?

Hi!

Yes, you can modify the path's data channels directly. When you add a control point, all the data passed to AddControlPoint() is stored in data channels (arrays) that you can then query for interpolated values along the spline. You can also read and write data directly from these. No need to wipe the path clean and redo everything. See the API documentation for the ObiPath class:

[Image: plZZDK0.png]

You can for instance set the third control point position to 10,0,0, and its color to red:

Quote:// winged points are value types (structs) so get a copy of it, modify and write back:
var point = blueprint.path.points[2];
point.position = new Vector3(10, 0, 0);
blueprint.path.points[2] = point;

// set the color to red:
blueprint.path.colors[2] = Color.red;

FYI, the reason why data is internally stored in separate arrays is because the interpolation method is different for each data type. For instance positions are interpolated using catmull-rom, filters/phases interpolated using constant interpolation, etc. It also allows for easy addition/removal of extra data channels for a path.
Reply
#3
Thanks a lot ! I'll try this solution.
Reply