(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:
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!