Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating rope path via script
#1
Hello, I was wondering there's a way to create the rope curve/shape (bezier or catmull) via script?
Like, if I want to make a spiral shape or something else at runtime.
Thanks in advance
Reply
#2
+ 1
Would be very interested in this as well.
Reply
#3
(15-12-2017, 02:20 AM)phoberman Wrote: + 1
Would be very interested in this as well.

Hi!

Obi/Scripts/Utils/ObiRopeHelper.cs is a good example on how to generate a rope in a fully procedural way.

cheers!
Reply
#4
Hi Jose –

That doesn't really answer the question, which wasn't about generating the entire rope procedurally, but just about creating a specific and precise curve (like a spiral) for a rope. The ObiRopeHelper.cs script only creates an extremely simple rope with two control points.

Maybe we should be able to figure out how to make a more complex shape from that script, but it's certainly not obvious, and a more relevant example would be appreciated (and if it's so easy to do, then it shouldn't be difficult to whip up an example).

I would also be interested in knowing whether it would be possible to import an existing spline, and if it isn't, I would like to put that forward as a feature request.

Certainly part of the problem is that the tools provided for editing Obi Catmull Rom Curves and Obi Bezier Curves are minimal and clunky. For instance, you can't place a control point at any specific location on the curve; you can only click 'Add Control Point' and work with whatever you get.
Reply
#5
(16-12-2017, 02:57 AM)phoberman Wrote: Hi Jose –

That doesn't really answer the question, which wasn't about generating the entire rope procedurally, but just about creating a specific and precise curve (like a spiral) for a rope. The ObiRopeHelper.cs script only creates an extremely simple rope with two control points.

Maybe we should be able to figure out how to make a more complex shape from that script, but it's certainly not obvious, and a more relevant example would be appreciated (and if it's so easy to do, then it shouldn't be difficult to whip up an example).

I would also be interested in knowing whether it would be possible to import an existing spline, and if it isn't, I would like to put that forward as a feature request.

Certainly part of the problem is that the tools provided for editing Obi Catmull Rom Curves and Obi Bezier Curves are minimal and clunky. For instance, you can't place a control point at any specific location on the curve; you can only click 'Add Control Point' and work with whatever you get.

Hi!

The sample script uses a spline with just 2 control points, but creating a more complex rope is just a matter of adding additional control points to the spline, like this:

path.controlPoints.Add(localStart-direction);
path.controlPoints.Add(localStart);
path.controlPoints.Add(midPoint1);
path.controlPoints.Add(midPoint2);
.
.
.
path.controlPoints.Add(midPointN);
path.controlPoints.Add(localEnd);
path.controlPoints.Add(localEnd+direction);

Note that the first and last control points are duplicated, because bezier curves need two endpoints to control curvature. Later today I´ll give you a more complex example.

Edit: For instance, to create a spiral-shaped rope, you do something similar to this:
Code:
float radius = 1;
float height = 0;
float ang = 0;

for (int i = 0; i < 50; ++i)
{
    path.controlPoints.Add(new Vector3(Mathf.Cos(ang)*radius,height,Mathf.Sin(ang)*radius));
    ang += 0.8f;
    height += 0.1f;
}

Inserting this code in the ObiRopeHelper.cs script in place of lines 36-39, yields this:

[Image: PVDV9iQ.png]

Regarding your question about importing existing splines, it is not currently supported and probably won't ever be as it is trivial to implement it yourself. Also there's lots of potential formats that people would want to import and it's not clear which ones would have to be supported, so it's a matter best left to each user and his/her specific needs. Importing a spline involves reading whatever file format you're interested in and adding the control point values to the path, as I just did in the example above.

For instance, if you had a .obj-like spline format that consisted of 3 floating point values per line in a plain text file, you'd: read each line of the file and then append the 3 values (x,y,z coords) as a new a control point. Do this in a loop until you reach the end of the file, and you're done (probably in less than 10 lines of code).

We are however working in improving the existing editor spline tools, as we are well aware of their shortcomings.

Let me know if you need further help. cheers!
Reply
#6
Jose – 

Huge thanks for the detailed example! I can't tell you how much I appreciate it.

- pH
Reply
#7
Sorry for inactivity on the post, this is exactly what I was looking for Jose, thanks for replying, as usual hehehe
Reply