Jump to content
bastien

new objects through script

Recommended Posts

Hello, I would need to dynamically create Bezier shapes and update them live (through code).

grosso modo : doing by code the : Tool > Brobuilder > Editor > new bezier shape action and then well editing the created objects through a script

Sorry for potential redundant but couldn't find anywhere the code documentation or sample for the API for pro users to do such actions.

sincerely

Share this post


Link to post
Share on other sites

Updating the path regularly will probably not be very performant, but here's the gist of how this would be done (note that this API will be changing in a future update):

var go = new GameObject();
go.AddComponent<pb_Object>();
go.AddComponent<pb_Entity>();
var bezier = go.AddComponent<pb_BezierShape>();
// bezier.Init();
// which is just doing this:
// Vector3 tan = new Vector3(0f, 0f, 2f);
// Vector3 p1 = new Vector3(3f, 0f, 0f);
// var m_Points = new List<pb_BezierPoint>()
// {
//     m_Points.Add(new pb_BezierPoint(Vector3.zero, -tan, tan, Quaternion.identity)),
//     m_Points.Add(new pb_BezierPoint(p1, p1 + tan, p1 + -tan, Quaternion.identity))
// };
// bezier.m_Points = m_Points;
bezier.Refresh();

 

Basically you're just feeding the pb_BezierShape component a set of bezier points (pb_BezierPoint) and calling Refresh.

Share this post


Link to post
Share on other sites

Hi there,  Here is a reduced code of my current problem : I am doing that :
 

. . .

GameObject pathObjectContainer = new GameObject();
pathObjectContainer.AddComponent<pb_Object>();
pathObjectContainer.AddComponent<pb_Entity>();
pathObject = pathObjectContainer.AddComponent<pb_BezierShape>();
pathPoints.Add (new pb_BezierPoint (new Vector3 (0, 0, 0),new Vector3 (0, 0, 0),new Vector3 (0, 0, 0), Quaternion.identity));

. . . .

updateVector = new Vector3 (10, 10, 0);

pathPoints.Add (new pb_BezierPoint (updateVectornew Vector3(0,0,0),new Vector3(0,0,0), Quaternion.identity));
pathObject.m_Points = pathPoints;
pathObject.Refresh ();

 

and This do the following result (the pic)

I can't understand why it add some moves in the z dimension, Do you have any idea ? changing the tan vectors don't have a positive impact.

I would like to have a bezier from (0,0,0) to (10,10,0) without any Z change

thank you !

Screen Shot 2018-01-15 at 14.31.59.png

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×