Sunday, 28 September 2014

Unity Bezier Curve WIP

Recently I have been learning Unity and playing around with scripting with C#. For my first project I needed to utilize bezier curves but they are not available by default in Unity. So I decided to create my own small bezier curve script.

To start I did some R&D in Houdini with a wrangle sop to figure out how to create a simple bezier curve. I then ported this into C# for Unity. I'v still got to create the rest of the script but here is the Houdini R&D along with the VEX code.

On the left is the Houdini Bezier curve and on the right is the Unity one.


vector p0 = point(@OpInput2, "P", 0);
vector p1 = point(@OpInput2, "P", 1);
vector p2 = point(@OpInput2, "P", 2);
vector p3 = point(@OpInput2, "P", 3);
float shift = fit(@ptnum, 0, 50, 0 , 1);
float blend = smooth(0, 1, shift);
float t = blend;
float tt = pow(blend, 2);
float ttt = pow(blend, 3);
float u = 1-t;
float uu = pow(u,2);
float uuu = pow(u,3);
vector B;
B = uuu * p0;
B += 3 * uu * t * p1;
B += 3 * u * tt * p2;
B += ttt * p3;
@P = B;

No comments:

Post a Comment